WebFaction
Community site: login faq

Hello

I have a problem with ChainedForeignkey

I changed ChainedForeignKey ("Category" .. in ChainedForeignKey ("material.Category" because I had the error Exception Value: need more than 1 value to unpack but I still can not link material and Category

why ?

model

class Demande_Expertise(models.Model):
    user = models.ForeignKey(User)
    material = models.ForeignKey("Material")
    categorie =  ChainedForeignKey("material.Category",
                              chained_field="material",
                              chained_model_field="name",
                              show_all=False,
                              auto_choose=True)                         
    droits_acces = models.CharField(_('val_champ'), max_length=150, choices = DROITS)
    groupe = models.ForeignKey(Group, blank = True, null= True, default = None)
    etat = models.CharField(_('val_champ'), max_length=150, choices = ETAT, default = '2')

class Category(models.Model):
    name = models.CharField(_('name'), max_length=50)
    slug = models.SlugField()

class Material(models.Model):
    name = models.CharField(_('name'), max_length=50)
    description = models.TextField(_('description'), blank=True)
    slug = models.SlugField()
    category = models.ForeignKey(Category, verbose_name=_('category'))
    created = models.DateField(_("creation date"), auto_now_add=True)

asked 14 Jan '14, 12:41

sesame
1124
accept rate: 0%


I see one problem here:

ChainedForeignKey("material.Category",

You're passing material.Category as a string, instead of passing it as an object. Try changing that line to:

ChainedForeignKey(material.Category,

I'm honestly not sure if that would cause the type of error you're seeing, but try fixing that, then see if you still have any errors.

permanent link

answered 14 Jan '14, 19:17

seanf
12.2k42136
accept rate: 37%

with this: categorie = ChainedForeignKey(material.Category,..

I get the error : AttributeError: 'ForeignKey' object has no attribute 'Category'

(16 Jan '14, 07:36) sesame

Ok, try using "ChainedForeignKey(material," instead.

(16 Jan '14, 14:22) seanf

with this :

categorie =  ChainedForeignKey(material.Category,
                              chained_field="material",
                              chained_model_field="name",
                              show_all=False,
                              auto_choose=True)

I get the error : AttributeError: 'ForeignKey' object has no attribute 'Category'

permanent link

answered 16 Jan '14, 07:32

sesame
1124
accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×910
×5
×2
×1

question asked: 14 Jan '14, 12:41

question was seen: 4,334 times

last updated: 16 Jan '14, 14:22

                              
WEBFACTION
REACH US
SUPPORT
LEGAL
© COPYRIGHT 2003-2020 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM