File: func_noerror_generic_foreign_key.py

package info (click to toggle)
pylint-django 2.0.13-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 660 kB
  • sloc: python: 1,807; sh: 13; makefile: 5
file content (17 lines) | stat: -rw-r--r-- 613 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
"""
Checks that Pylint does not complain about GenericForeignKey fields:
https://github.com/PyCQA/pylint-django/issues/230
"""
# pylint: disable=missing-docstring

from django.db import models
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes.fields import GenericForeignKey


class Ownership(models.Model):
    # for #230 the important bit is this FK field which doesn't
    # have any keyword arguments!
    owner_type = models.ForeignKey(ContentType, models.CASCADE)
    owner_id = models.PositiveIntegerField()
    owner = GenericForeignKey("owner_type", "owner_id")