T
T
tanyaa2017-07-22 20:00:23
Oracle
tanyaa, 2017-07-22 20:00:23

Why was the field removed from the table corresponding to the model when changing the field type to ChainedManyToManyField()?

Good evening.
When using the Django-smart-selects application to implement related selects, I try to change the fields of the models according to the example from the Django-smart-selects description, namely the example for the ManyToMany binding:

from smart_selects.db_fields import ChainedManyToManyField

class Publication(models.Model):
    name = models.CharField(max_length=255)

class Writer(models.Model):
    name = models.CharField(max_length=255)
    publications = models.ManyToManyField('Publication', blank=True, null=True)

class Book(models.Model):
    publication = models.ForeignKey(Publication)
    writer = ChainedManyToManyField(
        Writer,
        chained_field="publication",
        chained_model_field="publications", verbose_name='publication',db_column='publication'
)
    name = models.CharField(max_length=255)

Previously, the writer field was of type CharField, filled in manually in the form. When trying to screw in these related selects, the migration worked without errors, but the writer field was removed from the table corresponding to Book, and the form that uses this field now does not work. Question: Why is a field removed from the table that matches the model? how to return this field to the table and at the same time use Django-smart-selects for related selects? How to access the writer field from the book model from the form if it is not in the table?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexandra, 2017-07-27
@AK74U

I think the Oracle tag is completely unnecessary here.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question