Tuesday, July 19, 2016

Re: Model classes as containers to objects of another model

On Jul 19, 2016 12:16 PM, "Ajay D" <riffenstein@gmail.com> wrote:
>
> Hi All,
>
> I am fairly new to Django and find myself in the need to write to the group. 
>
> I have a django model "A", which has an "items" attribute. "items" is a list with objects of another django model "B" (there are no relationships between A and B). Everytime I create a new instance of "A", I need to make the attributes of all of the "B" objects editable via the template/form of "A".
>
> What would the obvious/ideal way to achieve this? 
>

You would probably create a custom form that had all of the fields that you require, with a custom form save() method that would take the form fields and save them into the right models.

https://docs.djangoproject.com/en/1.9/topics/forms/#building-a-form-in-django

Without any relationships, you have to do a bit more of the manual work yourself.

-James

--
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2Be%2BciXhi-ZUUm0WB5iJuyW-e5b46WfVgbpMWaMxF_QJ_3UxoQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment