marazmiki / django-generic-helpers Goto Github PK
View Code? Open in Web Editor NEWThe application provides some syntax sugar for working with Django's generic relations
The application provides some syntax sugar for working with Django's generic relations
Hello!
I use this package in my project for comments model:
from generic_helpers.models import GenericRelationModel
class Comment(GenericRelationModel):
user = models.ForeignKey(User)
text = models.TextField()
And now I want to create data migration:
def user_read_posts(apps, schema_editor):
User = apps.get_model("main", "User")
Post = apps.get_model("main", "Post")
Comment = apps.get_model("comments", "Comment")
comments = Comment.objects.all()
for comment in comments:
print (comment.content_object.__class__.__name__)
if isinstance(comment.content_object, Post):
comment.user.read_posts.add(comment.content_object)
class Migration(migrations.Migration):
dependencies = [
('main', '0039_auto_20160314_0906'),
]
operations = [
migrations.RunPython(user_read_posts),
]
But when I run it, django raises error: AttributeError: 'Comment' object has no attribute 'content_object'
.
When I call content_object in shell or views, it works perfectly.
What should I do??
generic_helpers/models.py:8: RemovedInDjango19Warning: django.contrib.contenttypes.generic is
deprecated and will be removed in Django 1.9. Its contents have been moved to the fields, forms, and
admin submodules of django.contrib.contenttypes. from django.contrib.contenttypes import generic
Must return a model.content_object.get_absolute_url()
This feature is exactly what I've been looking for, but there's a problem.
From README:
Features the application provides:
- Creating an arbitrary number of generic relation fields, both required and optional;
- Providing custom names for content_type and object_id columns
- You can define a whitelist (or a black one) of models that could (not) be written into the field
That sounds great, but is there any documentation explaining how to use those features? The example in the README doesn't include any arguments.
[20:42:03] xxx: напомни еще про generic relations helper
[20:42:28] xxx: там не поддерживается фокус типа post.comments_set.all() ?
[20:42:51] xxx: (для получения Comment привязанных через GR к Post)
[20:44:00] yyy: м
[20:44:09] yyy: я специально не делал. Но идея хороша
[20:44:17] yyy: пожалуй, надо будет попробовать замутиться
According to this, if a model has a customized save()
method, it would be overridden by GenericRelationField
while contributing to class.
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.