On Wed, Jun 8, 2016 at 9:25 AM, 'David Turner' via Django users <
django-users@googlegroups.com> wrote:

> Hi James
>
> Just one more quick question:
> I have two django models both containing the same information, temps and
> companies.
> The models both contain the following fields:
>
> odd days
> weekends
> nights
> emergencies
>
> Currently this allows me to filter on these fields in django admin.
> My question is would I be better treating these as a many to many model
> and using them that way and how would I filter them in django admin?
>
>
I have not used the admin much beyond the tutorial, so any answers from me
would be less than useful.

I don't quite understand the question. The only reason you would connect
them with a M2M would be if the two models had some sort of relationship
with each other. I don't think I have enough information to provide a
recommendation one way or the other. Ease of filtering in the admin should
have less influence than the business use case for model design.

I'm also not entirely sure what 'temps' refers to (temporary employees?),
which doesn't help my understanding of the question.

If you have two models that contain the same information, would it be more
prudent to combine them into a single more generic model and
separate/filter them by some sort of categorical field? For example, you
might have a model for a Car, and a model for a Truck, but both could
potentially be lumped together in a more generic model called Automobile,
or Vehicle (which is even more generic). Automobile could have a
'vehicle_class' attribute that would designate it as a 'car', 'truck', etc.
It's really dependent on the business use case and whether or not there is
enough difference between the two classes of vehicles to warrant having
separate models. Think of separate models from a very high level like "I
need all the car-like things over here, and all the people-like things over
here." Your models usually won't get more specific than that unless there
is a specific reason to do so.

Even if the business logic was different, but the underlying data structure
was the same, you could employ proxy models for 'Automobile' named 'Car'
and 'Truck' that have overlapping model methods with different behavior
(but are maintained within the same DB table).

I feel like I'm rambling on a tangent, so I'll stop there.

-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+unsubscr...@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%2BciUfDrBMkidPi-GF9Lw%3DOn-maoBgsAxKUpvfcma5QZG2fg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to