0

I am creating one model called Profile in which i have to add a url field for telegram profile. It takes username as input, but in output it should look like this: https://t.me/{username}. How I can create custom model field for this problem. Thanks by the way

My expectation is that, you only enter username, but in output it comes with prefix https://t.me/ and full url path will be https://t.me/{username}

0

2 Answers 2

2

Create a property function in your profile model.

@property
def get_telegram_link(self):
    return f"https://t.me/{self.telegram_username}"

When accessing the model link on your template or code use:

profile_instance.get_telegram_link()
Sign up to request clarification or add additional context in comments.

Comments

0

create a function under your model and use it in the template:

def get_tg_link(self):
    return f"https://t.me/{self.telegram_username}"

or override save function under your model

def save(self, *args, **kwargs):
    self.telegram_profile = f"https://t.me/{self.tg_username}"
    super().save(*args, **kwargs)

1 Comment

enes islam, Laban thanks for help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.