Django: get profiles having auth.Group as foreign key

170 views
Skip to first unread message

itsj...@gmail.com

unread,
Feb 10, 2015, 12:41:15 AM2/10/15
to django...@googlegroups.com
I have an model which uses auth.models Group as foreign key called Dashboard:-

<!-- begin snippet: js hide: false -->

<!-- language: lang-html -->

    class Dashboard(models.Model):
        d_name = models.CharField(max_length=200)
        d_description = models.CharField(max_length=200)
        d_url = models.CharField(max_length=200)
        d_status = models.CharField(max_length=200)
        owner = models.ForeignKey(Group)
       
        def __str__(self):return self.d_name

<!-- end snippet -->

my views.py is:-

<!-- begin snippet: js hide: false -->

<!-- language: lang-html -->

    def custom_login(request):
        if request.user.is_authenticated():
            return HttpResponseRedirect('dashboards')       
        return login(request, 'login.html', authentication_form=LoginForm)

    def custom_logout(request):
        return logout(request, next_page='/')

    def user(request):
        context = {'user': user, 'groups': request.user.groups.all()}
        return render_to_response('registration/dashboards.html', context, context_instance=RequestContext(request))

<!-- end snippet -->

and here using this dashboards.html i want to display the dashboards by using the Group_name which i will get as a result of **group.name** :-

<!-- begin snippet: js hide: false -->

<!-- language: lang-html -->

    {% extends "base.html" %}
    {% block content %}
    {% if user.is_authenticated %}
        <p>Welcome, {{ request.user.get_username }}. <br/>
        {% else %}
        <p>Welcome, new user. Please log in.</p>
    {% endif %}

    <ul>
    {% for group in groups %}
        <li>
            <strong>{{ group.name }}<strong> -
           
                {{ dashboards.d_name }}{% if not forloop.last %},{% endif %}
           
        </li>
    {% endfor %}
    </ul>



    {% endblock %}

<!-- end snippet -->

here i have mentioned all the supporting information for my problem, please let me know if there are any solution.

Collin Anderson

unread,
Feb 19, 2015, 1:14:18 PM2/19/15
to django...@googlegroups.com
Hi,

Sorry for the late reply. Do you just want something like this?

{% for dashboard in group.dashboard_set.all %}
 {{ dashboard.d_name }}
 etc
{% endfor %}

Collin
Reply all
Reply to author
Forward
0 new messages