Django: How to drop a proxy model and convert its values to super-type

StackOverflow https://stackoverflow.com/questions/23656771

  •  22-07-2023
  •  | 
  •  

سؤال

I am using proxy models in django, like this:

class A:
    ...

class B(A):
    class Meta:
        proxy = True

Now I want to delete the B model, and convert its values (table rows) to type A. Since proxy models use the same table as its parent, and there is no extra fields in my proxy model, it should not be necessary to touch the model table itself.

I have deleted the model (code) and removed the respective row from django_content_type, but django must store info somewhere else about which row is of which type, A or B. The rows inserted as B type, still doesn't show up as A type.

I am using south. The best solution would be to add this as an migration, but not strictly necessary.

How can I do this?

هل كانت مفيدة؟

المحلول

You don't need to do anything other than remove the content type. Proxy models aren't represented separately in the database at all (other than in content types). Proxy models are basically just helpers for doing things like adding a different default manager, changing ordering, etc.

You can also run django-admin.py schemamigration <appname> --auto to verify that there aren't any changes (South doesn't even consider Proxy models when making migrations).

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top