You can do that with proxy models which allows you to override and add
methods.
Of course if there is a need to really modify original model it gets tricky.
la 27. heinäk. 2019 klo 10.49 אורי kirjoitti:
> Hi,
>
> I had to change the following lines because tests failed:
>
> class
Hi,
I had to change the following lines because tests failed:
class Friend1(object):
def __str__(self):
return "User {} is friends with {}".format(self.to_user, self.from_user)
class FriendshipRequest1(object):
def __str__(self):
return "Friendship request from user {}
Django users,
I want to override def __str__ of models I'm using, but the models are
maintained by other developers. I think the __str__ is only used by the
admin interface. I found out that I can do something like this:
from django.contrib import admin
from django.contrib.sites.models import
This makes sense! Thanks!
On Monday, October 24, 2016 at 1:17:26 PM UTC+5:30, Deep Shah wrote:
>
> What kind of methods should be part of the models and what should be in
> the views? Can anyone give me an example of a method which should be in a
> Model than the views file?
>
--
You received
Any method that works *only* with the model data and is used in multiple
places in the application should be a part of the model.
Next, if you have functions that operate on multiple pieces of data (or
more than 1 model instances) you should put them in the view where they are
used. But if these
What kind of methods should be part of the models and what should be in the
views? Can anyone give me an example of a method which should be in a Model
than the views file?
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from
Whoops, wow that really was basic Python. Sorry for the spam; of
course I know there's a difference between calling a method and
calling an attribute...how embarassing. =)
Thanks for your help Anssi. Also thanks for not adding, ", you
moron!" to the end of each sentence...
On Feb 19, 9:47 am,
On Feb 19, 3:38 am, Gchorn wrote:
> Hello All,
>
> So in my models.py file, I have:
>
> class Player(models.Model):
> team = models.ForeignKey(Team)
> first_name = models.CharField(max_length=100)
> last_name = models.CharField(max_length=100)
>
Hello All,
So in my models.py file, I have:
class Player(models.Model):
team = models.ForeignKey(Team)
first_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100)
gp = models.IntegerField(max_length=2) #games played
mp =
9 matches
Mail list logo