Answer the question
In order to leave comments, you need to log in
How to make a filter from django models, fields are different, values are similar?
I'm starting to learn Django, for practice I want to implement an existing real estate agency website using Django.
The question is this, there are several types of real estate: an apartment, a house, a land plot, etc. it is clear that different data of these types can be implemented by models. An apartment can have an <floor of the apartment>/<total number of floors of the house>, for a house and a plot it is not necessary, just like a house can have a plot area, but a plot cannot have a house area. In addition, it is customary to measure plots in acres, and apartments in square meters.
Prices for apartments are fixed, while for new buildings there is a range of prices from and to, depending on the apartment in the new building.
Although it is more correct to make a new building a separate model, which can store links to apartments that belong to this new building. In fact, the new building is used as a real estate object (the model in our case), it just has 2 types of prices, minimum and maximum, and it’s not a fact that there will be a desire to create all available apartments for the new building and tie them, it’s quite possible that such logic will have to be followed further . And you need to search accordingly for a new building (in the latter case) in the field of the minimum price.
In general, the data seems to be similar, but I still can’t figure out how to search in them with a general search. Those. how, for example, to set such a query to the filter: "I have 15,000,000 rubles, what can I buy with them", a query for all models should return a new building with a minimum price of no more than 15,000,000 and a house and a plot, and, if any, any other Object type. And if you add to this the area is already more difficult, the apartment and the new building fall into square meters, the house too (the house itself), the house adjoining plot is no longer there, the plot as a separate type most likely will not fall, because. it has an area in acres (on the front, this can be bypassed by adding fields corresponding to the selected types of objects, but this can complicate the life of the seeker, but it is not desirable).
For myself, I would divide the interface by object type, it’s hard to imagine a person who doesn’t know what he is looking for with his money, but you can also understand the owner of the current site, if this was done, then someone needs it (it was in the TOR). But to store everything with one model and change the fields as the object is filled with data (now if a site is selected, its differing fields are shown, if the house is its own, the common fields remain unchanged) - it does not look healthy at all.
I'm not waiting for a ready-made solution, I'm just wondering how it is customary to solve such things in normal systems by sensible people. Often there is disparate data, different field names in the database, different models, but for sure there is a way to filter what you need.
elasticsearch? DjangoQ? Where to begin? What to read on the topic? Are there existing examples?
Answer the question
In order to leave comments, you need to log in
My vision.
The structure can be made of two types
1. Everything in one model, except for lists (lists are loaded via ForeignKey / ManyToManyField / OneToOneField links from other models or choices , they are set by the site administrator and are always static). Even if the model has 40 fields.
2. One base, where the general data. And a bunch of typical ones, related to the base model, but having their own unique fields. The lists, just like in the first version, were taken out into separate models or choices .
I would choose the second option.
Search. There are two options.
1. Sphinsk or other independent search programsworking with janga (Solr, Elasticsearch, Whoosh, Xapian).
2. Make the most janga and fight for logic and resources. That is, prescribe the entire search by hand, all the logic of possible options.
But I would choose the first option, there will be too many conditions and, in fact, writing a bicycle. And the second option is suitable for a more "simple" type of search.
Those. how, for example, to set such a query to the filter: "I have 15,000,000 rubles that I can buy with them",
but surely there is a way to filterin general - no
Here is an example. LCD Serebryany Park http://novostroev.ru/ - site for new buildings. See how it is.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question