M17-Project / REPEATER

Repeater Entry Provides Extremely Accurate and True Estimates of Range
2 stars 4 forks source link

Admin interface for upgrading a model instance superclass to a subclass #6

Open tarxvftech opened 2 years ago

tarxvftech commented 2 years ago

Let's say you have several Nodes in your database. You want to make them Repeaters, and Repeater inherits from Node. You need a way to do this more easily than typing commands into a shell, and it'd be nice to do it for several different models, not just Node->Repeater.

Here's an example of doing it by hand:

#convert a superclass instance to a subclass instance

    original = Node.objects.all()[0] #pick the one you want
    rp = Repeater(node_ptr=original) #node_ptr key name will change based on model, I think
    rp.save_base(raw=True)
    rp.__dict__.update(original.__dict__)
    rp.save()

Please provide a way to 'upgrade' a model to a subclass and fill in the new fields of the subclass in the django admin page. Ideally you could make this a separate django app and model-agnostic, but that might complicate things.