Skip to content
Advertisement

how to create django template tag for custom model

I’m new for django template tag. I am trying to display logged user payment_status and remaining_days on django html template. For this I wrote model and I don’t know how to write template tag for this. Request your help on this.

models.py
class User_subscription(models.Model):
    user_id = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, unique=True)
    subscription_id = models.ForeignKey(Subscription, on_delete=models.CASCADE)
    subscripted_date = models.DateTimeField()
    expired_date = models.DateTimeField()
    payment_status = models.CharField(max_length=50)
    payment_details = jsonfield.JSONField()

I want to display payment_status above in model and remaining_days = expired_date-subscripted_date

Advertisement

Answer

You should take a look at the Django documentation

But ideally, you should have the variables sent from your Django view and then in the templates, have the variables in double quotes {{ }}

In your case, you will have

{{expired_date - subscripted_date}}

But I encourage you to check out the documentation

Advertisement