doableware / djongo

Django and MongoDB database connector
https://www.djongomapper.com
GNU Affero General Public License v3.0
1.86k stars 351 forks source link

Django admin inline processing #666

Open AlexFoxalt opened 1 year ago

AlexFoxalt commented 1 year ago

Django admin pass not all fields to model creation process

Code

Admin model

@admin.register(SuggestChange)
class SuggestChangeAdmin(admin.ModelAdmin):
    list_display = (
        "reviewId",
        "applied",
        "accepted",
        "new",
        "country",
        "source",
        "author",
        "normalized_modified_attributes",
        "normalized_deleted_attributes",
        "normalized_added_attributes",
    )
    list_display_links = None
    list_editable = ("accepted",)
    search_fields = ("reviewId",)
    ordering = ("-timestamp",)

Mongo model

class SuggestChange(mongomodels.Model):
    _id = mongomodels.ObjectIdField()
    reviewId = mongomodels.CharField(max_length=100)
    country = mongomodels.CharField(max_length=100)
    category = mongomodels.CharField(max_length=100)
    source = mongomodels.CharField(max_length=100)
    timestamp = mongomodels.CharField(max_length=100)
    author = mongomodels.CharField(max_length=100)
    attributes = mongomodels.EmbeddedField(AttributeEmbedded, null=True)
    addedAttributes = mongomodels.ArrayField(AddedAttributeEmbedded, null=True)
    applied = mongomodels.BooleanField()
    accepted = mongomodels.BooleanField()
    new = mongomodels.BooleanField()

    class Meta:
        _use_db = "nonrel"
        db_table = "changes_to_review"

    def __str__(self):
        return self.reviewId

    def full_clean(self, exclude: Optional[Collection[str]] = ..., validate_unique: bool = ...) -> None:
        pdb.set_trace()

Traceback

The reason why i am here that when i run submit changes request in my admin panel, all 17 ORM objects passed to full_clean() func, but there are only 1 field that have some data, it is field that was changed. For example:

-> pdb.set_trace()
(Pdb) self._id
(Pdb) self.author
''
(Pdb) self.accepted
False
(Pdb) c

For some reason in 'exlude' var passed all fields that are empty

-> pdb.set_trace()
(Pdb) exclude
['_id', 'reviewId', 'country', 'category', 'source', 'timestamp', 'author', 'attributes', 'addedAttributes', 'applied', 'new']

Why these fields are empty? I really need only 2 fields presented for my program: _id and accepted, but no idea how to pass them to model functions.