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

33 lines
987 B
Python
Raw Permalink Normal View History

# -*- coding: utf-8 -*-
2024-01-15 20:20:10 +00:00
# bthlabs-jsonrpc-django | (c) 2022-present Tomek Wójcik | MIT License
from __future__ import annotations
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,
}