diff --git a/django_kepi/models.py b/django_kepi/models.py index 0befd72..1000cb5 100644 --- a/django_kepi/models.py +++ b/django_kepi/models.py @@ -323,43 +323,6 @@ class Actor(models.Model): ############################### -class YourPerson(models.Model): - - class Meta: - abstract = True - - name = models.URLField(max_length=256) - ftype = 'Person' - - def serialize(self): - return { - 'id': self.url_identifier(), - 'type': 'Person', - 'name': self.name, - } - - def url_identifier(self): - return 'https://example.com/user/{}'.format( - self.name, - ) - - def save(self, *args, **kwargs): - super().save(*args, **kwargs) - - self.get_actor() - - def get_actor(self): - - try: - result = Actor.objects.get(url=self.url_identifier()) - except Actor.DoesNotExist: - result = Actor(url=self.url_identifier()) - result.save() - - return result - -############################### - class UserRelationship(models.Model): class Meta: diff --git a/things_for_testing/models.py b/things_for_testing/models.py index 5706d9f..27478c8 100644 --- a/things_for_testing/models.py +++ b/things_for_testing/models.py @@ -2,19 +2,46 @@ from django.db import models from django_kepi import register_type from django_kepi import models as kepi_models -class ThingUser(kepi_models.YourPerson): +class ThingUser(models.Model): + + actor = models.OneToOneField( + kepi_models.Actor, + on_delete = models.CASCADE, + primary_key = True) + + ftype = 'Person' + + name = models.URLField(max_length=256) favourite_colour = models.CharField( max_length=256, default='chartreuse', ) + def save(self): + if self.actor_id is None: + self.actor = kepi_models.Actor( + url=self.url_identifier(), + ) + self.actor.save() + + # IDK why I have to do this explicitly: + self.actor_id = self.actor.pk + + super().save(self) + def serialize(self): + return { + 'id': self.url_identifier(), + 'type': self.ftype, + 'name': self.name, + 'favourite_colour': self.favourite_colour, + } - result = super().serialize() - result['favourite_colour'] = self.favourite_colour - - return result + def url_identifier(self): + return 'https://example.com/user/{}'.format( + self.name, + ) register_type('Person', ThingUser)