Django Admin

35 views
Skip to first unread message

Rafael E. Ferrero

unread,
Jan 18, 2016, 6:55:29 AM1/18/16
to django...@googlegroups.com
Hello everybody,

I'm gonna try to express my use case and hope you can help me to achieve this objective because i can't figure it out how i can resolve it.

1) I have a model of Products, with a lot of data for description, and other stuff.
(Let me say, ID, Short Description, Long Description,Minimun Amount Of Products Per Sale, Cost Price, Sale Price,
2) Then I have an other table (you can call it Sales), in this i need to save data of Products (Descriptions, Measure of units, and other specific data of my project)
(Let me say, ID, Short Description, Long Description, Sale Price, Date of Sale, Number of Document, etc.) where Short and Long Description, and Sale Price it's from Products model.

The Sales model DO NOT have to be related to Products with a Foreign key because we use Sales as Historic model too. So i need to take the data from Products and save it in Sales. So, I think that I can rewrite the method "save" in Sales model.

But... In the Admin Site, in the Sales form, I need a dropdown box of Products and when i choose one of them I need to populate the needed data in the fields of the Sales form, where the user can (If he wish), for example, add more text to Long Description field.

How I can put data of Products in the fields of Sales form without any relationship to Products, and how i can populate the fields based on the selected product??

Thanks in advance !!

Rafael E. Ferrero

Andreas Kuhne

unread,
Jan 18, 2016, 7:02:54 AM1/18/16
to django...@googlegroups.com
Hi Rafael,

I would use a plugin for django admin that creates an autocomplete field (django-selectable works). Then when the user chooses something in the autocomplete list, I would populate the other fields via ajax with the values that you need. That way you don'ẗ need a foreign key field (even though you could have it until the product is deleted) and you would get the functionality that you need.

Regards,

Andréas

--
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAJJc_8VScv11s-cwRE%2BCFXn2oH-29KL12iUk-%2BJHzD6A3TgVhw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Rafael E. Ferrero

unread,
Jan 18, 2016, 7:06:52 AM1/18/16
to django...@googlegroups.com
Thanks Andrea I'm gonna investigate this !!!


Rafael E. Ferrero

Reply all
Reply to author
Forward
0 new messages