I have created and tested a rule in the powerbi app that works fine in "view as", but when I publish my dataset with the rule, the report in the service is not working.
I am not sure if it has anything to do with that I am an admin on the project and using my own email to test out the filtering (though this isn't a problem in the app). Any thoughts? I realize this might be quite vague. My organization is still rather new to PBI.
Var CompanyPCC = CALCULATETABLE (
VALUES ( 'User Access'[PCC]),
FILTER ( 'User Access', 'User Access'[Login] = USERPRINCIPALNAME() )
)
RETURN
OR(
"ALL" IN CompanyPCC,
PATHCONTAINS(CompanyPCC,'Company'[Company PCC])
)
&&
Var Country= CALCULATETABLE (
VALUES ( 'User Access'[Country] ),
FILTER ( 'User Access', 'User Access'[Login] = USERPRINCIPALNAME() )
)
RETURN
OR(
"ALL" IN Country,
PATHCONTAINS(Country,'Company'[Company Profile Country])
)
&&
Var Brand= CALCULATETABLE (
VALUES ( 'User Access'[Brand] ),
FILTER ( 'User Access', 'User Access'[Login] = USERPRINCIPALNAME() )
)
RETURN
OR(
"ALL" IN Brand,
PATHCONTAINS(Brand,'Company'[Company Brand])
)
For RLS to work, a user needs to have read only permission in the workspace. Members or admins see everything by default. See:
https://learn.microsoft.com/en-us/power-bi/admin/service-admin-rls#using-rls-with-workspaces-in-power-bi
Related
Let's say I'm making a media library model, and there are these choices in named groups:
models.py
class MediaLibrary(models.Model):
MEDIA_CHOICES = [
('Audio', (
('vinyl', 'Vinyl'),
('cd', 'CD'),
)
),
('Video', (
('vhs', 'VHS Tape'),
('dvd', 'DVD'),
)
)
]
media_type = models.CharField(max_length=50, choices=Media_Choices)
If I make a request through DRF, it would return all the objects which match either "Audio" and "Video".
How can I filter the request so that it only returns objects under the "Audio" group. (Or the "Video" group.)
create a model manger and do filter as follows
class MediaManager(models.Manager):
def video_items(self):
return self.get_queryset().filter(media_type='Video')
---your models here--
objects = MediaManager()
then you can call in your views as MediaLibrary.objects.video_items(), similarly filer audio too.
I am trying to figure out the best (simplest) ways to call all the "Items" from my different User "Accounts."
The Account has the User ForeignKey.
class Acct ( models.Model ):
user = models.ForeignKey ( settings.AUTH_USER_MODEL)
The Item has the Account foreignKey.
class Items ( models.Model ):
acct = models.ForeignKey ( Acct )
So when I have a list of Acct's - what is the best way to get all the User's Items for the different accounts?
I can get all the Accounts with something like this:
a = request.user.acct_set.all ().filter ( active = 1 )
Now what is the next call to get the Items for those Accounts?
Only thing I can figure out is to add the User foreignKey to the Items also. (I would also have to add the Active field.)
I hope this makes sense. Thank you.
You don't need to add any more foreign keys - you can just traverse the existing relationships directly in one query like so:
# Fetch all the items associated with all accounts for this user
items = Item.objects.filter(acct__active=1, acct__user=request.user)
Not sure this is most efficient method, but it seems to be working.
id = request.user.acct_set.values_list ( 'id', flat=True ).filter ( active = 1 )
items = Item.objects.filter ( acct__in = id ) .order_by ( 'date' )
If there is a better way I would appreciate knowing it.
Thanks.
I have a choice tuple like that
CATEGORY_CHOICES = (
(DB_ENUMS.GENERAL.EMPTY, 'All'),
('Fashion and style',
(
(DB_ENUMS.CATEGORY.FASHION_AND_STYLE, 'All Fashion and Style'),
('Clothes/Shoes',
(
(1, 'string')
)
)
)
)
)
But this one
((1, 'string'))
is shown on the same level as
'All Fashion and Style'
Am I trying to use forbidden things? I found nothing about limits in documentation.
By default, Django only supports 2 levels of hierarchy in a choice field:
MEDIA_CHOICES = (
('Audio', (
('vinyl', 'Vinyl'),
('cd', 'CD'),
)
),
('Video', (
('vhs', 'VHS Tape'),
('dvd', 'DVD'),
)
),
('unknown', 'Unknown'),
)
However, there are some third-party apps like django-categories that provide the ability to have a hierarchy of choices.
I have a WorderOrder class that has predefined work order types:
class WorkOrder( models.Model ) :
WORK_TYPE_CHOICES = (
( 'hc', 'Heating and cooling' ),
( 'el', 'Electrical' ),
( 'pl', 'Plumbing' ),
( 'ap', 'Appliances' ),
( 'pe', 'Pests' ),
( 'ex', 'Exterior' ),
( 'in', 'Interior' ),
( 'ot', 'Others' ),
)
work_type = models.CharField( max_length = 2, choices = WORK_TYPE_CHOICES )
vendor = models.ForeignKey( Vendor, null = True, blank = True )
Therefore each order must have one work order type. Later down the road, a vendor can also be assigned to a work order.
I want the Vendor class to have a M2M relationship to the same work order choices in the WorkOrder class. In other words, each vendor are able to do one or many work types. For example, Bob's Plumbing can only do "Plumbing", whereas Solid Home Repair can do "Electrical", "Plumbing", "Exterior", and "Interior".
I understand I can create another table called WorkType and use foreign keys from WorkOrder and a M2M from Vendor, but since I feel I won't be changing the work type choices, I would rather have them predefined in models.py.
Also if I can predefine it in models.py, then I don't have to pre-populate the table WorkType during deployments and upgrades.
Some options for you:
create a model for work_type_choices, instantiate the records (hc, el, etc), then use a manytomany field, or
create a charfield and save CSV values to it (eg: "hc, el"), spliting/joining the value into it's elements as required, or
encapsule the above charfield and functions into a custom field and use that
leverage someone else's snippet, eg:
http://djangosnippets.org/snippets/1200/
I have a grouped category field. The problem is that I've created a search form, but when I try presente the form to the user in the template, it goes wrong.
models.py
MEDIA_CHOICES = (
('Audio', (
('vinyl', 'Vinyl'),
('cd', 'CD'),
)
),
('Video', (
('vhs', 'VHS Tape'),
('dvd', 'DVD'),
)
),
('unknown', 'Unknown'),
)
category = models.CharField(max_length=20, choices=MEDIA_CHOICES, verbose_name=_(u'Category'))
forms.py (search)
class SearchingForm(forms.Form):
"Search Box"
search = forms.CharField(max_length=100, required=False, label=(_(u'Search')))
music_kind = forms.MultipleChoiceField(choices=MEDIA_CHOICES, required=False,
label=(_(u'Kind')),
widget=forms.CheckboxSelectMultiple(),
)
template.html
{{ form.search }}
{{ form.place_kind }}
I show the form to the user like this, the problem is when I rendered with a browser I have something like this (in each line, it has a checkbox):
(('vinyl', 'Vinyl'), ('cd', 'CD'))
(('vhs', 'VHS Tape'), ('dvd', 'DVD'))
Unknown
I have delete the 'widget=forms.CheckboxSelectMultiple()' attribute it goes right, but I don't have a checkboxes. So, How I can do it with checkbox fields?
I think you have a data type mismatch here. You're wanting to store multiple values in a single CharField. Sure, you could save a dictionary of key-value pairs in there, but then you'd have to parse it back out into selections, and that's a huge pain.
I would move your MEDIA_CHOICES to a database table, and then in your SearchingForm, you can do a CheckboxSelectMultiple, and the form will behave as expected.
I'm not sure, but I wonder if choice groups are only for select boxes (not checkboxes).