Advice on template, list of objects from several models

26 views
Skip to first unread message

Anders

unread,
Oct 7, 2014, 7:15:21 PM10/7/14
to django...@googlegroups.com
Hello,
I am looking for some feedback on a seemingly simple problem.

My advertisement board project have 10+ models, one model per item
category (Cars, Pets, Apartments and so on). The common fields (title,
seller, location etc.) is defined in "MyAbstractModel" and inherited by
all other category models.

So far so good until it comes to rendering the items on the front-page
template.

Right now I just have 10+ blocks with for-loops in the template, listing
the 5 latest items in each category.
But I want to the user to be able to specify the order of categories in
the front page, and also which ones of the categories that should be
shown/hidden.


And that is where I am lost.
I guess I could have a "profile"-model which specifies the order and
visibility for each category, and a decent query filter and order_by
should do the trick I think.

But for the template I do not know, as the properties are different for
each category.
Maybe with a for-tag iterating the object list, and if there is a way to
figure out exactly what type of object it is use some if-tags display
the correct category properties maybe?



Any advice is welcome, and please feel free to ask if it seems unclear
(my thinking sometimes is hard to explain in words).

-A


Collin Anderson

unread,
Oct 8, 2014, 8:47:42 AM10/8/14
to django...@googlegroups.com, ap....@x76.eu
I'd personally try to get all of that stuff in _one_ database model if possible, with a "type" char field. That makes queries and ordering very easy.

Otherwise, yes, the next best option would be to have a database model that holds the ordering information and is somehow related to each model.
Reply all
Reply to author
Forward
0 new messages