On Aug 9, 7:54 pm, Lacrima <lacrima.ma...@gmail.com> wrote:
> Hello!
>
> I want to use django.views.generic.create_update.create_object to
> create and save object.
> But I need one field to be excluded from the form displayed.
> I can do it by setting exclude = ('somefield',) in the Meta class of
> my ModelForm subclass.
> If so I can't submit this form without an error, because this excluded
> field is required in my Model.
>
> I need to supply value for the excluded field programmatically to the
> create_object.
> How should I do this?
>
> My form:
> ----------
> from myapp.models import Question
> class QuestionForm(forms.ModelForm):
>     class Meta:
>         model = Question
>         exclude = ('quiz',)
> ----------
>
> My view:
> ----------
> from django.views.generic.create_update import create_object
> from myapp.forms import QuestionForm
> def add_question(request):
>     return create_object(request, form_class=QuestionForm)
> ----------
>
> My model doesn't allow 'quiz' field to be empty and I need to supply
> this value omitting the form.
> How should I do this?
>
> Any help will be really appreciated.
>
> If my question isn't clear I'll try to explain it more precisely, but
> my English is quite poor.
>
> With regards,
> Max.

Add to "quiz" field in Question model keyword blank=True (for varchar
type or "blank=True, null=True" for foreign key or datetime)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to