Problem with Form with ForeignKey field

25 views
Skip to first unread message

Drew Ferguson

unread,
Jan 14, 2014, 11:26:12 AM1/14/14
to django...@googlegroups.com
Hi

Django 1.5

I have a model which includes a ForeignKey field defined likes this

class Document(models.Model):
name = models.CharField(max_length=25, unique=True,
null=False,blank=False)
target = models.CharField(max_length=12,
choices=TARGETS,default='report')
content = models.TextField(null=False, blank=False)
fieldlist = models.TextField(null=True, blank=True)
multitarget = models.BooleanField(default=True, null=False,blank=False)
template = models.ForeignKey('Template',null=True,blank=True,
related_name='documents')
animal = models.ForeignKey('Animal',null=True,blank=True,
related_name='+')

the Animal table is quite large (>3000 records)

When a form template is called, there are no input fields rendered, just a
"save" button

If the Animal field is suppressed in the form with

class Meta(object):
model = Document
exclude = ['animal',]

the form renders correctly with appropriate input fields

Could someone suggest how to track down what is causing the problem with
the Animal selector when it is being generated? Is there a data issue
perhaps?

Thanks
--
Drew

Jonathan Pentecost

unread,
Jan 15, 2014, 3:44:41 PM1/15/14
to django...@googlegroups.com
Does it have anything to do with the related name of animal being `+`? I can't test this out just yet, but I don't THINK you can have a related_name as just `+`, I believe it needs to be a valid identifier.

Tom Evans

unread,
Jan 16, 2014, 4:50:52 AM1/16/14
to django...@googlegroups.com
On Wed, Jan 15, 2014 at 8:44 PM, Jonathan Pentecost
<pentecos...@gmail.com> wrote:
> Does it have anything to do with the related name of animal being `+`? I
> can't test this out just yet, but I don't THINK you can have a related_name
> as just `+`, I believe it needs to be a valid identifier.

'+' is perfectly valid for related_name, it means "do not create a
reverse relation".

https://docs.djangoproject.com/en/1.6/ref/models/fields/#django.db.models.ForeignKey.related_name

Cheers

Tom
Reply all
Reply to author
Forward
0 new messages