I’m building a database in django but I’ve run into a bit of an obstacle,
I’m trying to do something like this: there’s an object, and that object has two indices. each index has two values. This may sound confusing so let me put it this way:
Book has index alpha and index Beta
index alpha is at position (4,3)
index beta is at position (7,4)
Notice that the positions are stored sepparately instead of being in integer form ((4,3) instead of “43”)
In order to implement this on a DB, I’ve build a class for index and for Book, with a foreign key in index. Like so:
class index(models.Model):
book = models.ForeignKey(Books)
int1 = models.IntegerField()
int2 = models.IntegerField()
However, I wanted to simplify this. It’s gonna get messy later when I try to give other uses for the index class. (Not using it specificaly for the book class)
Ideally I’d create a custom multi value field which later I could use freely in my book class, like so:
class Book(models.Model):
title=...
publisher= ...
indexA=customMulti-valueField()
Is this possible? How would I define such a Field?
I’ve had a look at django documentation concerning custom field creation, but I don’t think it answers my problem.
The main concern here is having a mysql datatype that can store something like the python tuple.
Thanks.
If it only has 2 indices, I would just store them in IntegerFields and create a method that returns them both, like this:
Then you can use it like this: