Git Product home page Git Product logo

django-generic-helpers's People

Contributors

dependabot[bot] avatar marazmiki avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

django-generic-helpers's Issues

GenericRelation \does not work in Data Migrations

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??

Mame compatible with Django==1.9

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

documentation?

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.

automatic reverse generic relation?

[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: пожалуй, надо будет попробовать замутиться

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.