N
N
NyxDeveloper2021-05-04 16:15:55
MySQL
NyxDeveloper, 2021-05-04 16:15:55

How to forbid assigning id to fields of ForignKey of that object, whose certain field is equal to False?

There is a model:

class SomeObj(models.Model):
    name = models.CharField(verbose_name='Название', max_lenght=100)
    active = models.BooleanField(verbose_name='Активный', default=True)
    desc = models.TextField('Примечание', blank=True)


Other models have ForignKey fields on this model. You need to write something like checking if the project is active when assigning the id of this model in the field to another. I know that this can be done using signals and I can roughly imagine how, but signals need to be hung on all tables whose objects need to be checked when saving. Is there a way to do this in a more elegant and versatile way? Thank you!

Answer the question

In order to leave comments, you need to log in

4 answer(s)
J
Jorik86, 2018-10-05
@Dvoeglazov

I understand that in the resulting array you immediately want to group the values ​​​​by attributes.

[loc_work] => Array( тут 1 и более )
[profession] => Array(тут 1 и более )
[com_name] => Array(тут 1 и более )
[com_inds] => Array(тут 1 и более )

For this, group_concat may suit you
https://dev.mysql.com/doc/refman/8.0/en/group-by-f...

M
Maxim Timofeev, 2018-10-05
@webinar

If there are connections, they should be described, as I understand it, you need join

P
Pavel Novikov, 2018-10-05
@paulfcdd

do a JOIN and select all the data you need from all tables

M
maksam07, 2021-05-04
@maksam07

You can:
1. Validator for the form ( https://docs.djangoproject.com/en/3.2/topics/forms... )
2. Override the save() of the model ( https://docs.djangoproject.com/en/3.2 /topics/db/mo... )
3. Override form save() ( https://docs.djangoproject.com/en/3.2/topics/forms... )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question