kajic / django-model-changes Goto Github PK
View Code? Open in Web Editor NEWTracks the state and changes of django model instances.
License: MIT License
Tracks the state and changes of django model instances.
License: MIT License
Hello
The version on pypi is 0.15, but the latest version in this repo is 0.14, would it be possible for you to push those changes?
Thanks
Ben
I wonder why you explicitly exclude related fields (ForeignKey fields) in your current_state() method.
Could you elaborate on that? For me it's important to know whether I have a different related object (according to its ID) after the save().
I have found myself in a situation where for several models say X
, Y
and Z
, I would like to know when any change happens on them i.e. any create, update, delete. Is there any way to accomplish this using django-model-changes
?
Hey there,
I have integrated the app into a Model of mine. I put the ChangesMixin in front of the model description it inherits from. But I get the following error:
'ReverseSingleRelatedObjectDescriptor' object has no attribute 'cache_name'
As my Model does not contain a "cache_name", I guess the problem is from your app?
Greetings,
Tron
EDIT: Using Django 1.3
Related objects does not appear in previous_changes() method after object creation. For example, if your model has an "creator" field that references to auth.User and you set creator during creation, previous_changes() method does not show 'creator': [null, user].
To fix this problem, you could include next code in _save_state method:
def _save_state(self, new_instance=False, event_type='save'):
if new_instance and not self.pk: # new instance
self._states.append(self.new_state())
else:
# Pipe the pk on deletes so that a correct snapshot of the current
# state can be taken.
if event_type == DELETE:
self.pk = None
# Save current state.
self._states.append(self.current_state())
...
And add the new function too:
def new_state(self):
"""
Returns a ``field -> None`` dict of the initial state of the instance.
"""
field_names = set()
[field_names.add(f.name) for f in self._meta.local_fields]
[field_names.add(f.attname) for f in self._meta.local_fields]
return dict([(field_name, None) for field_name in field_names])
If you are ok with that, I can make a PR to the library.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.