How to

31 views
Skip to first unread message

Balaji Shetty

unread,
May 13, 2019, 3:30:08 AM5/13/19
to django...@googlegroups.com
Hi
Consider the demo Example

models.py
from django.db import models

class Musician(models.Model):
    first_name = models.CharField(max_length=50)
    last_name = models.CharField(max_length=50)
    instrument = models.CharField(max_length=100)

class Album(models.Model):
    artist = models.ForeignKey(Musician, on_delete=models.CASCADE)
    name = models.CharField(max_length=100)
    release_date = models.DateField()
    num_stars = models.IntegerField()

class Fan(models.Model):
    artist = models.ForeignKey(Musician, on_delete=models.CASCADE)
    Conutry = models.CharField(max_length=100)
    Name = models.CharField(max_length=100)
    
Here We have to keep Track of Musician Album as well as all Fan/Follower
of respective Musician.


Admin.py

class AlbumInline(admin.TabularInline):
    model = Album

class FanInline(admin.TabularInline):
    model = Fan

class MusicianAdmin(admin.ModelAdmin):

    inlines = [AlbumInline,FanInline , ]

# code to register these 3 models
---------------------------------------------
I have seperate Login User Account for Album 
I have seperate Login User Accpunt for Fan

My Question is
I want to add only Album record in Album Login Account
I want to add only Fan Record in Fan Login Account

Currently 
In both login, Album and Fan Records can be added. How cam i restrict these
?

--
Mr. Shetty Balaji S.
Asst. Professor
Department of Information Technology,
SGGS Institute of Engineering & Technology, Vishnupuri, Nanded.MH.India
  Mobile: +91-9270696267

Nelson Varela

unread,
May 17, 2019, 10:02:13 AM5/17/19
to Django users
Take a look at django permissions/groups models where you can make groups and put these models in each group. After that you add the users to the group so they can only edit models in that group

Balaji Shetty

unread,
May 18, 2019, 7:36:43 AM5/18/19
to django...@googlegroups.com

Hello Nelson Varela  ..... Thank you very Much for your reply.

One more query - Should i check the permission ( by writing the extra code ) for extra Security.
Definitely Your solution works well for me. I have implemented the same logic. But i want to know through the code



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/e4a2ad0a-901c-4862-b313-9492783628cb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages