Question

I have a class and it's modelForm.

class UserGoal(models.Model):
    user = models.ForeignKey(User)
    goal = models.ForeignKey(Goal)
    deadline = models.DateTimeField(blank=True, null=True)
    goalETA = models.DateTimeField(blank=True, null=True)
    def __unicode__(self):
        return u'%s, %s, %s ' %(self.user, self.goal, self.deadline)

class partialGoalSetForm(ModelForm):
    class Meta:
        model = UserGoal
        fields = ('deadline', 'goalETA') 

This code works fine for having just 2 fields (deadline and goalETA) be in the form. However, if I remove one from the list:

 fields = ('deadline')

Then, I get the following error:

django.core.exceptions.FieldError: Unknown field(s) (a, e, d, i, l, n) specified for UserGoal

It seems to be tokenizing 'deadline' by characters. Very weird.

The solutions I've tried include:

 fields = ('deadline')

 fields = 'deadline'

 field = ('deadline')

 field = 'deadline'

None of which work.

Any suggestions? Thank you for your help.

Was it helpful?

Solution

As fields only has one item, it requires a trailing comma to be treated as a tuple. Otherwise, it treated as the string "deadline".

fields = ('deadline',)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top