These are chat archives for miznat/django

11th
Feb 2015
rredkovich
@rredkovich
Feb 11 2015 12:06
First of all creating new branch and installing django-simple-history.
For further installing simplicity adding this package to requirements.txt
Than including it in settings file, all this this stuff one can find in instruction https://django-simple-history.readthedocs.org/en/latest/usage.html#install
Than again according to instruction adding history field to Venue model - basic models for all places (Restaurant, Masjid)

rredkovich
@rredkovich
Feb 11 2015 12:12
Now trying populate history
python manage.py populate_history --auto
Which gives "No registered models were found", googling it gives not much, for example http://stackoverflow.com/questions/24209655/history-of-a-manytomanyfield-in-django-simple-history
Probably we need syncdb, but let's make other steps in instruction
rredkovich
@rredkovich
Feb 11 2015 12:18

It seems that there will be changes in actual code:

admin.site.register(models.Restaurant, SimpleHistoryAdmin)
# admin.site.register(models.Restaurant, RestaurantAdmin)

So i will expect following changes in admin.py for saving old admin style for Restaurant model, but for now let's just try what will happens with one new line of code.

rredkovich
@rredkovich
Feb 11 2015 12:25
This message was deleted
Ok, app starts but raise error on trying go to history in one of restaurants
'Options' object has no attribute 'simple_history_manager_attribute'
rredkovich
@rredkovich
Feb 11 2015 12:33
Reversing to population
Let's use option for manual model
python manage.py populate_history Venue
Unable to find model < Venue >

python manage.py populate_history Restaurant
Unable to find model < Restaurant >
Maybe it's something with model inheritance... Documenation silent about this, so let's check source code

Long story short they use get_model for resolving it

from django.db.models.loading import get_model
...
model = get_model(app_label, model)

Let's try to play with this in django shell

rredkovich
@rredkovich
Feb 11 2015 12:38
>>> get_model('api', 'Venue')
>>> get_model('api', 'Restaurant')
<class 'api.models.Restaurant'>
>>> get_model('api', 'Masjid')
<class 'api.models.Masjid'>
Looks like this method couldn't return Base model...
rredkovich
@rredkovich
Feb 11 2015 13:21
Which is normal behaviour, but it's strange that south doesn't add tables to children if parent changed... and this appear only if field if HistoricalRecords type...
rredkovich
@rredkovich
Feb 11 2015 13:39
let's checkout with debugger
rredkovich
@rredkovich
Feb 11 2015 13:51

Aha! simple_history.models.HistoricalRecords have different behaviour on real model (Restaurant) and abstract (Venue).
Call stack for real Model:

> /vagrant/mir_rayan/local/lib/python2.7/site-packages/simple_history/models.py(43)__init__()
-> try:
(Pdb)

> /vagrant/mir_rayan/local/lib/python2.7/site-packages/simple_history/models.py(52)contribute_to_class()
-> self.manager_name = name
(Pdb) 

> /vagrant/mir_rayan/local/lib/python2.7/site-packages/simple_history/models.py(59)add_extra_methods()
-> def save_without_historical_record(self, *args, **kwargs):
(Pdb) 

> /vagrant/mir_rayan/local/lib/python2.7/site-packages/simple_history/models.py(76)finalize()
-> history_model = self.create_history_model(sender)
(Pdb) 

> /vagrant/mir_rayan/local/lib/python2.7/site-packages/simple_history/models.py(96)create_history_model()
-> attrs = {'__module__': self.module}
(Pdb) 

> /vagrant/mir_rayan/local/lib/python2.7/site-packages/simple_history/models.py(128)copy_fields()
-> fields = {}
(Pdb) 

> /vagrant/mir_rayan/local/lib/python2.7/site-packages/simple_history/models.py(150)get_extra_fields()
-> user_model = getattr(settings, 'AUTH_USER_MODEL', 'auth.User')
(Pdb) 

> /vagrant/mir_rayan/local/lib/python2.7/site-packages/simple_history/models.py(192)get_meta_options()
-> meta_fields = {
(Pdb)

For Abstract last call is

> /vagrant/mir_rayan/local/lib/python2.7/site-packages/simple_history/models.py(59)add_extra_methods()
-> def save_without_historical_record(self, *args, **kwargs):