Giter Site home page Giter Site logo

coleifer / django-relationships Goto Github PK

View Code? Open in Web Editor NEW
368.0 20.0 101.0 129 KB

Descriptive relationships between auth.users (think facebook friends and twitter followers, plus more)

Home Page: http://django-relationships.readthedocs.org

License: MIT License

Python 98.78% HTML 1.22%

django-relationships's Introduction

django-relationships

Descriptive relationships between auth.users:

In [4]: john.relationships.friends()
Out[4]: [<User: Yoko>]

In [5]: john.relationships.following()
Out[5]: [<User: Paul>, <User: Yoko>]

In [6]: john.relationships.followers()
Out[6]: [<User: Yoko>]

In [7]: john.relationships.blockers()
Out[7]: [<User: Paul>]

In [8]: paul.relationships.blocking()
Out[8]: [<User: John>]

You can create as many types of relationships as you like, or just use the default ones, 'following' and 'blocking'.

From, To and Symmetrical

Relationship types define each of the following cases:

  • from - 'following', who I am following
  • to - 'followers', who is following me
  • symmetrical - 'friends', we follow eachother

Relationship types can be login_required, or private, and if you want to make a relationship type unviewable (i.e. you may not want to allow users to see who is blocking them), simply give it a unmatchable slug, like '!blockers'.

Admin Interface

Relationships hook right into the pre-existing User admin, and appear below the 'Groups' inline.

Installation

python setup.py install

OR

put the relationships folder on your python-path

django-relationships's People

Contributors

arnee avatar bradmontgomery avatar coleifer avatar epicserve avatar eryckson avatar jezdez avatar juanriaza avatar mlavin avatar paltman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

django-relationships's Issues

This project needs a maintainer.

Hi @coleifer,

This repository seems to lack maintenance, I propose myself as a new maintainer.

Could you give me the right to push in your repository or just transfer it on my account in github?

Thank you!

django-notification support

It would be nice to send notifications when relationships are added.

I think the following notices should be sent:
you started following (default: no mail sent)
you stopped following (default: no mail sent)
started following you (default: mail sent)
you started blocking (default: no mail sent)
you stopped blocking (default: no mail sent)
started blocking you (default: no mail sent)

Additionally... It could also send notifications to your followers:
started following (default: no mail sent)

I think the notifications when you stop following/blocking should only be sent to yourself. Also, because notifications should be translated, I'm not sure it's possible to provide generic notifications for relationships other than following/blocking, which is why I only focused on those 2.

I'll come up with a patch, but I wanted to get feedback on the idea first :)

Tests failes (fixtures aren't loaded?)

I've been trying to use django-relationships in my project. I've installed it by

pip install django-relationships

Unfortunately tests are failing. It looks like the fixtures from

tests/fixtures/relatioships.json

aren't loading. I tried it in my project (with other plugins etc.) and on clean installation of django.

Output from my console - http://pastie.org/1572664

accessor clash error when try to test.

I found a stange error. When i make validation with my models it's validating but when i try to run tests there is a problem with umessages (umessages? hmm may be it's a model from django-userena)

~$ python manage.py validate
0 errors found
~$ python manage.py test
Creating test database for alias 'default'...
Error: One or more models did not validate:
relationships.relationship: Accessor for field 'from_user' clashes with related field 'User.from_users'. Add a related_name argument to the definition for 'from_user'.
relationships.relationship: Reverse query name for field 'from_user' clashes with related field 'User.from_users'. Add a related_name argument to the definition for 'from_user'.
relationships.relationship: Accessor for field 'to_user' clashes with related field 'User.to_users'. Add a related_name argument to the definition for 'to_user'.
relationships.relationship: Reverse query name for field 'to_user' clashes with related field 'User.to_users'. Add a related_name argument to the definition for 'to_user'.
umessages.messagecontact: Accessor for field 'from_user' clashes with related field 'User.from_users'. Add a related_name argument to the definition for 'from_user'.
umessages.messagecontact: Reverse query name for field 'from_user' clashes with related field 'User.from_users'. Add a related_name argument to the definition for 'from_user'.
umessages.messagecontact: Accessor for field 'to_user' clashes with related field 'User.to_users'. Add a related_name argument to the definition for 'to_user'.
umessages.messagecontact: Reverse query name for field 'to_user' clashes with related field 'User.to_users'. Add a related_name argument to the definition for 'to_user'.

models do not validate

Hye, Am Ian, working on a project... Trying to inco-operate the app to my django project...
I was doing testing, and the following error is shown:

Error: One or more models did not validate:
auth.user: Accessor for m2m field 'relationships' clashes with related m2m field 'User.related_to'. Add a related_name argument to the definition for 'relationships'.
auth.user: Reverse query name for m2m field 'relationships' clashes with related m2m field 'User.related_to'. Add a related_name argument to the definition for 'relationships'.
auth.user: The model User has two manually-defined m2m relations through the model Relationship, which is not permitted. Please consider using an extra field on your intermediary model instead.
auth.user: Accessor for m2m field 'relationships' clashes with related m2m field 'User.related_to'. Add a related_name argument to the definition for 'relationships'.
auth.user: Reverse query name for m2m field 'relationships' clashes with related m2m field 'User.related_to'. Add a related_name argument to the definition for 'relationships'.

I believe it has to something with the hack you have in models.py file:

HACK

field = models.ManyToManyField(User, through=Relationship, symmetrical=False, related_name='related_to')

TODO: Look into this issue; Remove The comment below after Tests #field.contribute_to_class(User, 'relationships')

I thought I could avoid the issue by commenting out the parts, but, I get a diffent error altogether :

ERROR: test_site_behavior (relationships.tests.tests.RelationshipsTestCase)

Traceback (most recent call last):
File "/home/ian/workspace/myproject/src/myproject/util/core/relationships/tests/tests.py", line 231, in test_site_behavior
self.assertQuerysetEqual(self.walrus.relationships.all(), [self.john, self.paul])
File "/usr/lib/pymodules/python2.6/django/db/models/manager.py", line 117, in all
return self.get_query_set()
File "/usr/lib/pymodules/python2.6/django/db/models/fields/related.py", line 484, in get_query_set
return superclass.get_query_set(self).using(db).next_is_sticky().filter(*(self.core_filters))
File "/usr/lib/pymodules/python2.6/django/db/models/query.py", line 550, in filter
return self._filter_or_exclude(False, *args, *_kwargs)
File "/usr/lib/pymodules/python2.6/django/db/models/query.py", line 568, in _filter_or_exclude
clone.query.add_q(Q(_args, *_kwargs))
File "/usr/lib/pymodules/python2.6/django/db/models/sql/query.py", line 1128, in add_q
can_reuse=used_aliases)
File "/usr/lib/pymodules/python2.6/django/db/models/sql/query.py", line 1026, in add_filter
negate=negate, process_extras=process_extras)
File "/usr/lib/pymodules/python2.6/django/db/models/sql/query.py", line 1191, in setup_joins
"Choices are: %s" % (name, ", ".join(names)))
FieldError: Cannot resolve keyword 'related_to' into field. Choices are: _message_set, avatar, date_joined, email, emailvalidation, first_name, forum_post_set, from_users, groups, id, is_active, is_staff, is_superuser, last_login, last_name, logentry, originating_user, password, rate, reputation, subscription, target_user, to_users, user_permissions, username, vote

Please check this out... Cheers.

Remove user from following when blocked

I am working on incorporating this great django app into a site I am building. One suggestion, if a user blocks another user that is following them, shouldn't the user that is blocked be removed from the "following" list? For example if Susan was following Tommy, and Tommy decided to block Susan, it should remove Susan from from the "following" list for Tommy.

Django 1.5 CustomUser.first_name and Admin

It appears to be that you are using the field first_name for displaying the relationships on the admin but there is no guarranty that a CustomUser would have this field. I think the only field that would be there for sure is USERNAME_FIELD [get_username()]. I'm pretty new with Django so please correct me if I'm wrong.

Adding/Removing via Ajax

Hello, I'm wondering how one would go about implementing an AJAX follow/unfollow button - AJAX really isn't my strong point and I notice that in the docs you mention it's supported but I'm really not sure how to implement it. I'd really appreciate being pointed in the right direction/given a working example. Thanks heaps :)

Ordering relationships by time created

I've figured out how to go about making a simple notification system, but now I'm completely stumped on how to reverse the order of the queryset to show the latest followers first. Where in your code is one able to reverse/change the ordering of the queryset returned? The following piece of code returns a list of the users followers...

def followers(self):
    return self.get_related_to(RelationshipStatus.objects.following())

I've tried reversing the order on the ordering tuple in the model's meta and that doesn't seem to work (only changes the ordering in the admin), and I can't seem to order_by created because the queryset returns a User object which bears no link to the time the relationship was made. Any ideas? It's possible to use the reversed filter in the template but then I end up with the entire list of followers reversed, and if I try and slice this I merely get the first three followers in reverse. I'd really appreciate any guidance :)

Relationship Status Not Found

Hello,

I include /relationships/relationship_add.html/ in profiles template so that when a user go to another users profile and if they are not friends, the user will be able to add the other user.

After inserting it and testing, I’m getting Template Syntax error, “Relationship status not found”

What I’m I missing? Kindly help me out!

__init__() got an unexpected keyword argument 'core_filters'

Hi,

I tried to use django-relationships with latest Django 1.4.x and got the error :

TypeError at /relationships/foxmask/

__init__() got an unexpected keyword argument 'core_filters'

Request Method:     GET
Request URL:    http://localhost:8000/relationships/foxmask/
Django Version:     1.4.1
Exception Type:     TypeError
Exception Value:    

__init__() got an unexpected keyword argument 'core_filters'

Exception Location:     /home/foxmask/Django-VirtualEnv/tglr/lib/python2.6/site-packages/relationships/models.py in __get__, line 258
Python Executable:  /home/foxmask/Django-VirtualEnv/tglr/tglr/../bin/python
Python Version:     2.6.6
Python Path:    

['/home/foxmask/Django-VirtualEnv/tglr/tglr',
 '/home/foxmask/Django-VirtualEnv/tglr/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg',
 '/home/foxmask/Django-VirtualEnv/tglr/lib/python2.6/site-packages/pip-1.1-py2.6.egg',
 '/home/foxmask/Django-VirtualEnv/tglr/lib/python2.6/site-packages/Django-1.4.1-py2.6.egg',
 '/home/foxmask/Django-VirtualEnv/tglr/lib/python2.6/site-packages/ipython-0.13-py2.6.egg',
 '/home/foxmask/Django-VirtualEnv/tglr/lib/python2.6/site-packages/PyMySQL-0.5-py2.6.egg',
 '/home/foxmask/Django-VirtualEnv/tglr/lib/python2.6/site-packages/django_registration-0.8-py2.6.egg',
 '/home/foxmask/Django-VirtualEnv/tglr/lib/python2.6/site-packages/django_profiles-0.2-py2.6.egg',
 '/home/foxmask/Django-VirtualEnv/tglr/lib/python2.6/site-packages/django_debug_toolbar-0.9.4-py2.6.egg',
 '/home/foxmask/Django-VirtualEnv/tglr/lib/python2.6',
 '/home/foxmask/Django-VirtualEnv/tglr/lib/python2.6/plat-linux2',
 '/home/foxmask/Django-VirtualEnv/tglr/lib/python2.6/lib-tk',
 '/home/foxmask/Django-VirtualEnv/tglr/lib/python2.6/lib-old',
 '/home/foxmask/Django-VirtualEnv/tglr/lib/python2.6/lib-dynload',
 '/usr/lib/python2.6',
 '/usr/lib/python2.6/plat-linux2',
 '/usr/lib/python2.6/lib-tk',
 '/usr/lib64/python2.6/lib-tk',
 '/home/foxmask/Django-VirtualEnv/tglr/lib/python2.6/site-packages']

Server time:    mar, 4 Sep 2012 13:49:11 +0200

I've made another virtualenv and installed just Django 1.3.3 with django-relationships + django-debug-toolbar and got no error .

Data Fixture

Sorry, what data fixture? How will I reload it? Or are you talking about the runtest?

Some erros in Django 1.7

Cannot use add() on a ManyToManyField which specifies an intermediary model. Use relationships.Relationship's Manager instead.
What this mean?

Django 1.2 compatibility

Testing with latest django svn, django-relationships fails :\

File "/home/mat/work/libe/djaz/apps/relationships/models.py", line 78, in <module>
    RelatedManager = create_many_related_manager(RelationshipManager, rel=Relationship)
File "/home/mat/work/virtualenvs/django-dev/lib/python2.6/site-packages/django/db/models/fields/related.py", line 439, in create_many_related_manager
    through = rel.through
AttributeError: type object 'Relationship' has no attribute 'through'

In 1.2, create_many_related_manager expect "rel" as a second argument, and not "through". I tried a dummy fix:
RelatedManager = create_many_related_manager(RelationshipManager, rel=field.rel)

But it didn't work, that just creates another problem:
init() got an unexpected keyword argument 'source_col_name'
/home/mat/work/libe/djaz/apps/relationships/models.py in get, line 92

Queryset chaining

Because of the way JOINs are being set up, chaining filters on relationship fields is creating some bad SQL.

i.e.
In [10]: j.relationships.filter(to_users__from_user=j)
Out[10]: [<User: Paul>, <User: Yoko>, <User: charles>]

In [11]: j.relationships.filter(to_users__from_user=j, to_users__status=1)
Out[11]: [<User: Paul>, <User: Yoko>, <User: charles>]

In [12]: connection.queries.pop()
Out[12]: 
{'sql': u'SELECT "auth_user"."id", "auth_user"."username", "auth_user"."first_name", "auth_user"."last_name", "auth_user"."email", "auth_user"."password", "auth_user"."is_staff", "auth_user"."is_active", "auth_user"."is_superuser", "auth_user"."last_login", "auth_user"."date_joined" FROM "auth_user" INNER JOIN "relationships_relationship" ON ("auth_user"."id" = "relationships_relationship"."to_user_id") WHERE ("relationships_relationship"."from_user_id" = 2  AND "relationships_relationship"."status" = 1 ) LIMIT 21',
 'time': '0.000'}

In [13]: j.relationships.filter(to_users__from_user=j).filter(to_users__status=1)
Out[13]: [<User: Paul>, <User: Paul>, <User: Yoko>, <User: charles>, <User: charles>]

In [14]: connection.queries.pop()
Out[14]: 
{'sql': u'SELECT "auth_user"."id", "auth_user"."username", "auth_user"."first_name", "auth_user"."last_name", "auth_user"."email", "auth_user"."password", "auth_user"."is_staff", "auth_user"."is_active", "auth_user"."is_superuser", "auth_user"."last_login", "auth_user"."date_joined" FROM "auth_user" INNER JOIN "relationships_relationship" ON ("auth_user"."id" = "relationships_relationship"."to_user_id") INNER JOIN "relationships_relationship" T4 ON ("auth_user"."id" = T4."to_user_id") WHERE ("relationships_relationship"."from_user_id" = 2  AND T4."status" = 1 ) LIMIT 21',
 'time': '0.000'}

Not Getting How It Relate

Hi, I tried visiting localhost:8000/relationships , I'm getting 'RelationshipStatus matching query does not exist' So I created an add template. After visting localhost:8000/relationships/add, I'm getting "Page not found (404)" what's the problem? Am I missing something?

Creating notifications

Hello, how would one go about adding notifications for a user? That is, notifying on a user on their profile page when someone follows them?

Django-relationships: RelationshipStatus matching query doesnt exist

I am using django-relationships for the system of followers and following in my django app. I followed the documentation and added the app 'relationships' in my INSTALLED_APPS. And after it by running 'python manage.py shell' ,I did the following according to the documentation

>>> john = User.objects.get(username='john')
>>> rel = john.relationships.add(jane)

But the problem is :

Traceback (most recent call last):
File "<console>", line 1, in <module>
File "build/bdist.macosx-10.7-intel/egg/relationships/models.py", line 96, in add
  status = RelationshipStatus.objects.following()
File "build/bdist.macosx-10.7-intel/egg/relationships/models.py", line 13, in following
  return self.get(from_slug='following')
File "/Library/Python/2.7/site-packages/django/db/models/manager.py", line 132, in get
  return self.get_query_set().get(*args, **kwargs)
File "/Library/Python/2.7/site-packages/django/db/models/query.py", line 349, in get
  % self.model._meta.object_name)
DoesNotExist: RelationshipStatus matching query does not exist.

I also copied the folder of django-relationships in my main project folder but it didnt work. Do I have to manually create relationshipstatuses ? How to do it ? Or what is other solution for it ? Thanks!

Django 1.7 Errors in application

Using this app in django 1.7b4 raises the following error

Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 427, in execute_from_command_line
utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 391, in execute
django.setup()
  File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
  File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 106, in populate
app_config.import_models(all_models)
  File "/usr/local/lib/python2.7/dist-packages/django/apps/config.py", line 190, in import_models
self.models_module = import_module(models_module_name)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
  File "build/bdist.linux-x86_64/egg/relationships/models.py", line 8, in <module>
  File "build/bdist.linux-x86_64/egg/relationships/compat.py", line 7, in <module>
  File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/__init__.py", line 136, in get_user_model
return django_apps.get_model(settings.AUTH_USER_MODEL)
  File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 187, in get_model
self.check_ready()
  File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 119, in check_ready
raise RuntimeError("App registry isn't ready yet.")
RuntimeError: App registry isn't ready yet.

Add get_blacklisted(), get_blacklisting()

Since constants defines RELATIONSHIP_BLOCKED it would be nice to have get_blacklisted(), get_blacklisting() too in UserRelationships.

It should be pretty trivial :)

Add is_in_relationship()

is_in_relationship (or is_in_relationship_with), with a status argument, would be a useful method to add to UserRelationships.

So would be is_blacklisted(), is_blacklisting(), is_followed(), is_following() but that's just lazyness :-)

Django 1.7 support

I just pushed some really bad hack for this repo to work under django 1.7. Don't know if anyone is still using this package and might want this update. It was really bad practice, I basically copied the compatible method version from django 1.4, and if there's anyone who familiar with django might be able to fix the issue with a better practice.
Here's the fix: https://github.com/thisiscam/django-relationships

Better sites support

What about to support sites through a callable [lambda: Site.objects.get_current()] instead trust only to settings.SITE_ID. This will help me (and others) using dynamic site id (through middleware), for instance.

"manage.py dumdata auth.user" returns Error

Hi!.

When I want to dump data to a fixture, i get this error:

Error: Can't resolve dependencies for auth.User in serialized app list.

Cheking my apps, y found that the problem is this app, most exactly an Field ManyToMany that is added in execution time, i don't know how work it, there says that is hack, but i understand it..

In the models.py this lines:

field = models.ManyToManyField(User, through=Relationship,
symmetrical=False, related_name='related_to')

And this

HACK

field.contribute_to_class(User, 'relationships')

If i comment these lines, i can do dump without problems, can someone explain me how that works?

You can add a symmetrical relationship without approval

I'm not sure if I'm just being dense, but it seems to me when you look at tests.py and the method test_adding_symm lines 411 - 422, that this isn't the correct behavior. According to how I'm reading this this, John can make friends with The_Walrus without The_Walrus approving the friend request. Is that correct and if so, should this be corrected? If I was The_Walrus I'm not sure I would want John to have the ability to connect as a friend without my approval.

Still not working.

I've syncdb already, and Relationship statuses have been added in my admin dashboard. Yet when I visit localhost:8000/relationships/add , I'm still getting page 404 error. Anytips? Thanks.

Non Python package data isn't installed correctly

With the introduction of setuptools, it's required to have the package data not only in the manifest template but also in the package_data parameter of setup().

Fixed in jezdez/django-relationships@2c35ef06e54dd3491e7cc686c8169ce1789a64ca

Code explaination

Hello, could please someone explain this?
Why does the relationship_list view function returns another function _relationship_list? Is there any reasons to separate the code calling another function?
Also, does the underscore in _relationship_list have any particular meaning (private)?
Thanks

Friend Requests

Looks awesome! Are there any plans to put in friend requests?

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.