Wednesday, September 29, 2010

Re: What is the correct way to copy an object from one model to a similar model?

You can use also introspection if the number of attributes is high.
http://stackoverflow.com/questions/3818825/python-what-is-the-correct-way-to-copy-an-objects-attributes-over-to-another

2010/9/29 Yo-Yo Ma <baxterstockman@gmail.com>:
> I have two models that are identical in structure except one has 2
> extra fields. The second one is used for record keeping and is never
> edited by users. The system takes the first model and copies it to the
> second model, adding some extra meta information, all when a certain
> action is performed against the first model.
>
> What is the best practice for this?
>
> spam.attribute_one = foo.attribute_one
> spam.attribute_two = foo.attribute_two
>
> Or, is there a pattern that works well?
>
> --
> 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+unsubscribe@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
>
>

--
Antoni Aloy López
Blog: http://trespams.com
Site: http://apsl.net

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment