Reputation: 19975
My user object with rest framework has an avatar_id
and a cover_id
. But Instead of displaying that to the API, I want it to be the actual avatar URL and cover URL already.
My User
model:
avatar_id = models.IntegerField()
cover_id = models.IntegerField()
My UserAvatar
model:
id = models.IntegerField(primary_key=True)
user_id = models.IntegerField()
file_id = models.IntegerField()
My Files
model:
id = models.IntegerField(primary_key=True)
filename = models.CharField(max_length=255)
Same concept with UserCover
.
How do I remove the avatar_id
from the results of /users/
and add a avatar field with the actual avatar filename?
Upvotes: 0
Views: 98
Reputation: 2390
I'm not sure I understand your question correctly, but here what I think the problems are. Reading your question, I assumed that you are a beginner, so I answered as such. Sorry if it's not the case.
I don't know what is a UserCover
, but here's what your models could look like:
from django.contrib.auth.models import User
class UserProfile(models.Model):
# Link to Django normal User (name, email, pass)
user = models.ForeignKey(User, unique=True)
# Any information that a user needs, like cover, wathever that is, age, sexe, etc.
avatar = models.CharField(max_length=255)
Or like this if a will be reused often :
class Avatar(models.Model):
# name = ...
# description = ...
path = models.CharField(max_length=255)
class UserProfile(models.Model):
user = models.ForeignKey(User, unique=True)
avatar = models.ForeignKey(Avatar, unique=True)
# other data
Upvotes: 1