if and Is between loan

Asked

Viewed 58 times

-1

Thus, I created a user table and a business, both inherit from the Django user table. Perfect, both your users and tables. But I have a menu and a profile page.html and wanted that in this menu appeared the photo and name of who was logging in and the same on the profile page more as I have user.user and user.negocio I don’t know how to make this logic if you are logged in with user.user to show such thing but show user.business someone wants to waste time and help me?

1 answer

1


I’m not sure I understand your question, but come on.

From what I understand, you have the two classes (User and Business) that inherit from User and want to check in the template if the user who is logged in belongs to the class User or Business.

In that situation, it would be something like:

{% if request.user.is_authenticated %}
    {% if request.user.usuario %}
        <img src="{{request.user.usuario.foto.url}}">
    {% elif request.user.negocio %}
        <img src="{{request.user.negocio.foto.url}}">
    {% endif %}
{% endif %}

Here, I am assuming that both User and Business have a photo field of the Imagefield type.

But this is not the best way to do something like this in Django. Ideally you should have 2 groups (using Django.contrib.auth.models.Group) and link each user to one of the groups according to their needs.

If you want, put the project on Github and send the link that I help you with.

Hug!

  • hi friend excellent logging, the more appeared the following error Exception Type: RelatedObjectDoesNotExist at /accounts/login/&#xA;Exception Value: User has no usuario. Use Django admin Accounts for login

  • face I think it worked, the night I confirm you, but if gave saved my life

  • opa friend, tried and did not work, it shows the company, more then when soon in the user it does not show, and case within the user’s if.user I ask the user’s photo.negocio.foto it accepts

  • Hello Mauricio. Can you send me your code so I can have a look? Especially models.py, views.py and the html you’re trying to make?

  • https://github.com/MauMaster/Pet-Aqui of course, but inside the menu is not with that if, Else Elif

  • I appreciate any help, it’s part of my TCC to desperate

  • I even published another post https://answall.com/questions/369788/desdenti%C3%A7%C3%A3o-entre-dois-tipos-de-usu%C3%A1rios-usando-if/369799#369799

  • Mauricio. I was preparing the answer when you closed the topic. hehe

  • I’ve reopened, why I haven’t managed yet, I appreciate you helping me friend

  • I saw the other question there. Allan’s answer is quite complete. But, I created a new.py models that I believe would make your database more optimized. Check it out and see if you’re interested: https://pastebin.com/0De0Sk0u

  • Another thing. As I said, it’s not the right way to do it but, for a moment of despair, it works well. hehe Anything, we are there.

  • look where I’ve gone, if you can help me https://answall.com/questions/370822/if-else-entre-dois-tips-user

Show 7 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.