F
F
firstrow2011-01-22 15:09:42
Django
firstrow, 2011-01-22 15:09:42

Django.Theory: Implementing multiple checkboxes?

Hello.
I write a service about the sale / rent of real estate.
I am interested in the following question:
There is an object, let's call it for example "House",
the house has the following parameters:
1. "Name"
2. "Type of heating" with the following options

  • Gas heating
  • Central heating
  • Oil (diesel) heating
  • Electric heating
  • Floor heating
  • Solar panels
  • wood heating

3. "Kitchen"
  • Built-in kitchen
  • kitchen niche
  • Kitchen-dining room
  • kitchen island
  • open kitchen

etc.
All parameters are strictly defined in the code, i.e. there is no need to create/edit in the database.
All options in the form must be implemented as a checkbox with the possibility
of multiple selection.
Actually, the question is how to implement a model in django so that:
1. The form refills multiple "checkboxes"
2. Search by these parameters, for example, find a house with "Gas heating" and "Built-in kitchen"
3. How to save the selected options in the database?
Option number one:
Implement everything with ForeignKey Cons
: resource-intensive, many queries...etc
Option number two:
Store an entry like "kitchen: option1, option2, option4" in the database
But how, with this option, is it normal to implement a search, display a form with checked fields.
I will be grateful for advice.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Riateche, 2011-01-22
@Riateche

If the set of checkboxes is fixed, you need to create a field in the "house" model for each of the checkboxes.
Put a checkbox on each field in the form. Only the standard template will not work, you will have to create your own so that the checkboxes are shown in several lists. But it's not scary.
The search is trivial - everything is in one table.

D
dr1v3, 2011-06-06
@dr1v3

Not safe. I recommend posting the source code next to it.

A
andrey_kl, 2011-06-06
@andrey_kl

What's stopping you from putting it in a gallery?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question