Skip to content

Conversation

@rohitvarkey
Copy link
Contributor

Django 1.6 is not supported anymore to the extent that even documentation for that version is not available on the official website. There have been some discussions here about porting to Django 1.9 (Ref: #4 and #8) and this PR takes a stab at it. This PR makes the following major changes:

  1. Port to Django 1.9 (I've gone through and changed errors obtained to their newer versions wherever possible)
  2. Remove south migrations files.
  3. Add the follow package (completely ported to 1.9. Upstream PR - Port to Django 1.9 caffeinehit/django-follow#25). The package hasn't been maintained in 3 years or so and its doubtful that the PR will get accepted.
  4. Create a requirements.txt for easy set up of virtual environments.

From the test suite provided there is 1 failing test which I haven't been able to fix. I also suspect that the REST API's might be affected with the change to DRF 3.x, notably due to the removal of nested writable serializers. I will look into the REST API's but I'd appreciate any help with the failing test. This is the traceback obtained.

ERROR: test_task_manager (django_project.tests.ProjectTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/rohitvarkey/Code/django-project/django_project/tests.py", line 134, in test_task_manager
    asset.add_task(self.task)
  File "/Users/rohitvarkey/Code/django-project/django_project/managers.py", line 49, in add_task
    if self._filter(ObjectTask).filter(task=task).count() == 0:
  File "/Users/rohitvarkey/Code/django-project/django_project/managers.py", line 44, in _filter
    return self._object_tasks
  File "/Users/rohitvarkey/.virtualenvs/peragro2/lib/python2.7/site-packages/django/contrib/contenttypes/fields.py", line 251, in __get__
    f = self.model._meta.get_field(self.ct_field)
  File "/Users/rohitvarkey/.virtualenvs/peragro2/lib/python2.7/site-packages/django/db/models/options.py", line 582, in get_field
    raise FieldDoesNotExist('%s has no field named %r' % (self.object_name, field_name))
FieldDoesNotExist: Asset has no field named 'ObjectTask'

Regards,
Rohit

@sueastside
Copy link
Contributor

Seems there was some renaming in django GenericForeignKey -> GenericRelation

managers.py:21

from django.contrib.contenttypes.fields import GenericRelation

class ObjectTaskMixin(models.Model):
_object_tasks = GenericRelation('ObjectTask',
content_type_field='content_type',
object_id_field='object_pk')

seems to fix that error. But is it correct?

Do you also get an error with runserver in settings.py
TEMPLATES var not allowing DEBUG : True?

I also get the following when testing:

Traceback (most recent call last):
File "/home/sueastside/Projects/django-project/follow/tests.py", line 76, in test_follow_http
self.assertEqual(302, response.status_code)
AssertionError: 302 != 500

Any idea what that is about?

@rohitvarkey
Copy link
Contributor Author

@sueastside Sorry about that. I had changes that fixed those errors locally but didn't push. Just pushed now.

@rohitvarkey
Copy link
Contributor Author

Seems there was some renaming in django GenericForeignKey -> GenericRelation

managers.py:21

from django.contrib.contenttypes.fields import GenericRelation

class ObjectTaskMixin(models.Model):
_object_tasks = GenericRelation('ObjectTask',
content_type_field='content_type',
object_id_field='object_pk')

There is also a GenericForeignKey in Django 1.9! I went with that while porting but GenericRelation seems to work better here! Although now it gives an error complaining that FieldError: Unsupported lookup 'pk' for TextField or join on the field not permitted.

This seems to be coming from the definition the object_pk attribute of ObjectTask in models.py:302

class ObjectTask(models.Model):
    """
    """
    task = models.ForeignKey(Task, verbose_name=_('task'), related_name="%(class)s_tasks")

    content_type = models.ForeignKey(ContentType,
            verbose_name=_('content type'),
            related_name="content_type_set_for_%(class)s")
    object_pk = models.TextField(_('object ID'))
    content_object = GenericForeignKey(ct_field="content_type", fk_field="object_pk")

EDIT: It was the functions defined in the ObjectTaskMixin that was causing the errors.

@rohitvarkey
Copy link
Contributor Author

The latest commit fixes the failing test and from the printed output, the tasks seems to be added and removed correctly!

sueastside added a commit that referenced this pull request Mar 11, 2016
WIP: Port to Django 1.9 and use latest version of packages
@sueastside sueastside merged commit b623988 into peragro:master Mar 11, 2016
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

Successfully merging this pull request may close these issues.

2 participants