models.py 806 B

1234567891011121314151617181920212223242526272829303132
  1. from django.db import models
  2. from django.utils.encoding import python_2_unicode_compatible
  3. @python_2_unicode_compatible
  4. class TestModel(models.Model):
  5. field1 = models.CharField(max_length=255)
  6. field2 = models.IntegerField()
  7. def __str__(self):
  8. return '%s%d' % (self.field1, self.field2)
  9. @python_2_unicode_compatible
  10. class RelatedToTestModel(models.Model):
  11. field = models.ForeignKey(TestModel, on_delete=models.CASCADE)
  12. def __str__(self):
  13. return self.field
  14. @python_2_unicode_compatible
  15. class SearchableTestModel(models.Model):
  16. field1 = models.CharField(max_length=255)
  17. field2 = models.IntegerField()
  18. def __str__(self):
  19. return '%s%d' % (self.field1, self.field2)
  20. @staticmethod
  21. def autocomplete_search_fields():
  22. return 'field1'