Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't access moderated object attributes #134

Open
ursomniac opened this issue Jun 3, 2015 · 5 comments
Open

Can't access moderated object attributes #134

ursomniac opened this issue Jun 3, 2015 · 5 comments

Comments

@ursomniac
Copy link

from your_app.models import MyModel

foo = MyModel.objects.get(pk=1)

foo.dict
{ ... all the things... }

foo.moderated_object.changed_object.dict
Traceback (most recent call last):
File "", line 1, in
AttributeError: 'MyModel' object has no attribute 'moderated_object'

This doesn't match the behavior in the "How django-moderation works" part of the docs.

@ryuusenshi
Copy link
Contributor

What's happening is that your models are not getting registered.

To check which models are registered you can do:

from moderation import moderation

print moderation._registered_models

If you get an empty dict, it's because you haven't registered any models. Now if you have moderation.helpers.auto_discover() in your urls.py what you need to know is that the urls.py file is not loaded if you're using the shell (i.e. ./manage.py shell).

In order for your models to properly register, you should do this before you do anything else in you shell session:

from moderation.helpers import auto_discover
auto_discover()

This might fix all the other problems you've been having, as well.

@ryuusenshi
Copy link
Contributor

I got the example_project to work with django 1.7.8.

Created a ExampleUserProfile and it didn't show up until it was approved.

@ryuusenshi
Copy link
Contributor

@ursomniac Did this fix your problems? I'm unable to reproduce the problem.

@ursomniac
Copy link
Author

@ryuusenshi Yes - things are behaving properly in the shell now - THANKS!

BUT - you still can get the behavior I described if you go through the Django admin. (i.e., non-superuser user creates an object that immediately goes live). This isn't ABSOLUTELY critical (because I'm not intending to let anyone but superusers to have access to the Django Admin), but I'd like to know what - if anything - I'm doing wrong.

(and thanks for your patience!)

@ursomniac
Copy link
Author

I'm back to square 1.

If I incorporate Django REST framework, it ignores django-moderation: Event objects created through moderation - though 'pending' - appear in the Event table. HOWEVER, using moderation in the shell returns the "correct" results (i,e., Event.objects.all() only returns approved objects) even though there are objects in the Event table that are unapproved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants