My goal is to create a struct-like object in Django PostgreSQL, such as:
specs.coordinate.x
specs.coordinate.y
specs.coordinate.z
x,y,z should therefore be subclasses of coordinate. They should be me mutable as well, wherefore named tuples cannot be used.
I have tried it using the new dataclass:
from django.db import models
from dataclasses import dataclass
class Specs(models.Model):
name = models.CharField(max_length=80)
age = models.IntegerField()
@dataclass
class coordinate:
x: float
y: float
z: float
However the coordinate x,y,z items are not visible in pgAdmin:
What am I doing wrong? Is there any better approach for this than with dataclass?
If your goal is simply to use the syntax:
specs.coordinate.x
in your datasheet you can simply use aOneToOne
Relation.This also allows for the special case, that either all Coordinates values have to be set or none.
Now you can use Specs just like the a Dataclass.