1
0
bthlabs-jsonrpc/packages/bthlabs-jsonrpc-django/example/bthlabs_jsonrpc_django_example/things/models.py

31 lines
950 B
Python
Raw Normal View History

# -*- coding: utf-8 -*-
# django-jsonrpc-django | (c) 2022-present Tomek Wójcik | MIT License
from django.db import models
class Thing(models.Model):
name = models.CharField(max_length=255)
content = models.TextField()
created_at = models.DateTimeField(auto_now=False, auto_now_add=True)
modified_at = models.DateTimeField(auto_now=True, auto_now_add=False)
is_active = models.BooleanField(default=True, db_index=True)
owner = models.ForeignKey(
'auth.User', null=True, blank=True, on_delete=models.CASCADE,
)
class Meta:
verbose_name = 'thing'
verbose_name_plural = 'things'
def to_rpc(self):
return {
'id': self.pk,
'name': self.name,
'content': self.content,
'created_at': self.created_at,
'modified_at': self.modified_at,
'is_active': self.is_active,
'owner_id': self.owner_id,
}