Well, I found solution.
``CreateWithInlinesView `` works perfectly with ``OneToOneField`` (after all, 1-to-1 is just a foreign key with constraint), but my main model here is ``Comment``, not ``Task``. So I should set ``Comment`` as ``model`` field in this view and ``Task`` as ``inline``. It looks silly. I will create custom form or review my model structure.
On Wednesday, April 22, 2015 at 3:38:30 PM UTC+3, Ilya Kazakevich wrote:
Thank you, that may work, but I feel that I reinventing wheel here.Actually, there are inline_formset and CreateWithInlinesView (from django extras) and they do exactly what I want, but they only support ForeignKey, not OneToOne. Looks like I need to extend them to support OneToOne.
On Wednesday, April 22, 2015 at 2:40:56 AM UTC+3, Vijay Khemlani wrote:What about and old-school DetailView?def get_context_data -> Creates the two forms and puts them in the contextdef post -> Validates and process the formsOn Tue, Apr 21, 2015 at 7:41 PM, Ilya Kazakevich <kazakev...@gmail.com> wrote:Hello,--I have several models with one-to-one relation. For exampleclass Task(models.Model):initial_comment = models.OneToOneField('Comment') # A pack of other fieldsclass Comment(models.Model)body = RichTextField()# A pack of other fieldsI want to create "create view" based on form, that gives user ability to create task and initial comment there.1) I can't use CreateView because it is based on only one model2) I can't use ModelForm because it is based on only one model3) I can create several forms, but I can't join them into one formset (forms are different)4) I feel "inlineformset_factory" (InlineFormSet) should be used here, but I am not sure it suits best. Is there any 3rd party Django app to do that?Sure I can create form myself, but I do not want to copy/paste all fields, their types, localized labels, validations and so on. I just want to list their names (like "fields" attibute).If you wonder why do I need one-to-one: Comments are used heavily in other places and have different relations with different models.Thank you.Ilya.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com .
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users .
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/e5254d86- .c237-4192-bf1e-4e2d96722a9f% 40googlegroups.com
For more options, visit https://groups.google.com/d/optout .
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/4558d41f-cb8f-47de-8482-ad4fbab05def%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment