John
John
use signal
i doesn't have any idea about that did u have any example
John
and i use django for rest api only so is its work for that ?
international
Can anybody help me
007
How to dynamically set 'DJANGO_SETTINGS_MODULE' in celery.py , Based on different django settings
Anshu
Anshu
Harsh
what is that
In your model class
Override the default save model and call the superclass's save method at the end.
Lemme send you an example
Harsh
John
Salesforce
Any one needs python rest api django full course by durga sir ping me.
Kajal
LEX
Python - ERP
Sequence of Path matters?
urlpatterns = [
path('meetups/', views.meetups,name="all-meetups"),
path('meetups/success',views.confirm_registration,name="confirm-registration"),
path('meetups/<slug:meetup_slug>',views.meetupDetails,name="meetup-detail"),
]
Nayan
Hi can someone help me !!
I have 5 groups , each group have different permission which i have assign to them
Now how can i use this groups in views.py with function based so that the views will behave based on group permission also i think i need to check which user is associated to which group ?? I am confused please help !!!
Damilola
Damilola
Damilola
Damilola
Damilola
Nayan
I saw some examples with cbv and fbv but one could not able to get it in both the cases how to use it with 5 groups , the example are available only with 1 group
Ex for fbv
Def somegroup(user)
If user:
Return user.group.filter(name='student').count() == 0
What if user belongs with 2 groups at the same time or it refers to some other group ... It is confusing me up.
Nayan
The decorator we use here is
@user_passes_test(some group)
Damilola
Nayan
Sure will do it .
Pravin
Inuk
@boiyelove sorry, mistake in spam protection, i'll look into it
Inuk
Sure will do it .
this is what @boiyelove said:
https://docs.djangoproject.com/en/3.2/topics/auth/default/#permissions-and-authorization
Use custom logic for texting user has the right perm
https://docs.djangoproject.com/en/3.2/topics/auth/default/#django.contrib.auth.mixins.UserPassesTestMixin
This is the permission required decorator for FBV;
https://docs.djangoproject.com/en/3.2/topics/auth/default/#the-permission-required-decorator
This is the mixin for CBV
https://docs.djangoproject.com/en/3.2/topics/auth/default/#the-permissionrequiredmixin-mixin
If you're worried your user belongs to multiple groups (although I'm unsure why this is a problem), you can
1. create group such that permission 1 belongs to group a but not group b
OR
2. Do your permission checks based on "permissions" directly and not based on groups.
Nayan
Damilola
Damilola
Damilola
Abdalwhab
How create form like Google forms in Django
I need add field without add it in models file
Abdalwhab
James
Hellow. Any one who can help me best site or youtube chanel that is good for integrating django with angular js
Neeraj
Neeraj
Neeraj
Or use geeky show chanel also for this
James
Enes
https://www.hizliresim.com/1wdkwhi
Enes
please help guys i have a modal which is get data with ajax for product but when i try to use imagefield in this modal it says that you need to serialize
Enes
$('.add-quick-view').click(function(){
var catid;
catid = $(this).attr("data-productid");
$.ajax(
{
type:"GET",
url: "/getproduct/",
data:{
product_id: catid
},
success: function( data )
{
document.getElementById("prdct_title").innerHTML = data.product_name;
document.getElementById("prdct_price").innerHTML = data.product_price+'$';
document.getElementById("prdct_details").innerHTML = data.product_details;
document.getElementById("prdct_photo").innerHTML = data.product_photo;
document.getElementById("prdct_title").innerHTML = data.product_name;
console.log(data)
}
})
});
Enes
def get_product_info(request):
if request.is_ajax and request.method == "GET":
product_id = request.GET['product_id']
print(product_id)
obj = Product.objects.get(id=product_id)
product_name = getattr(obj, 'name')
product_photo = getattr(obj, 'photo')
product_price = getattr(obj, 'price')
product_details = getattr(obj, 'details')
return JsonResponse({"product_name":product_name,'product_price':product_price,'product_photo':product_photo,'product_details':product_details}, status = 200)
else:
return JsonResponse({}, status = 400)
Enes
**url
path('getproduct/', views.get_product_info, name='get-product-info'),
Enes
the error on browser console
TypeError at /getproduct/
Object of type ImageFieldFile is not JSON serializable
Request Method: GET
Request URL: http://127.0.0.1:8000/getproduct/?product_id=2
Enes
the problem is in there;
in views : product_photo = obj.photo.url
in js: document.getElementById("prdct_photo").src= data.product_photo;
Chikal
Excuse me.. I have a question..
#ask
how to submit data from form <form>, and fill the link with its data from form using javascript ?
example, I have a code:
<script type="text/javascript">
function showInput() {
document.getElementById('display').innerHTML =
document.getElementById("name").value;
}
</script>
the form is:
<form>
<input name="name" type="text" id="name">
<input type="submit">
</form>
<button onclick="showInput()"></button>
<span id='display'></span>
then there is a link :
<a href='https://api.whatsapp.com/send?phone=6281909555392&text=Halo%20Iam%20--I want full fill this part with the data from input name--%20wanna%20ask">
how to do it ? is it possible?
If I click the showInput button, the name display by span id=display, but inside the link its not appear, how to do it ?
Anonymous
Hi all, I need help. How to start learning Django? Can you please share any ideas guy's.
Swati
Hey.. Can django be integrated wd ai software.. I want to make a project for my final yr engineering.. Can someone suggest mr ideas n how to do that?
khairul
Sahil
Hello guys,
I don't have web development knowledge at all but I kNow Python.
Then how to start learning django ?
Sahil
Any very basic tutorial for it ?
Sahil
Also do we need to learn rest api along with django ?
Sahil
Django + Database + Rest ??
Anshu
William
William
While implementing on views you need to import the permission classes and use it permission_classes list
Anonymous
hello, what's the problem here, error message 'ItemAdmin' object has no attribute 'urls', https://pastebin.com/Wtfz3hMN, https://pastebin.com/ci8pxb5W
Jaya
Hello, can anyone tell me how to filter many to many fields, i want to get only that field which contains some of the user present in that many to many field
luna
filter many to many with user__in=[User.objects.filter(**kwargs))]
Jaya
See i have a class with a field group users which is many to many field and a field group id and i want to get the group from the group id and name of users present in group users
William
Jaya
Ok
Jaya
class groupchat(models.Model):
groupusers=models.ManyToManyField(User,blank=True)
groupid=models.Foreignkey(Group,on_delete=cascade)
groupname=models.CharField(max_length=255)
This is the model and i have group id and name of two users now i want to fetch the group name with the help of data i have
Jaya
Hope you get my question or do i need to explain it again😅
William
Use prefetch_related on the group users field.
William
Jaya
rtg
Hi! How can i upload image (imageField) to static/img/installation/ folder?
rtg
Is this correct:
William
Mani
What's easiest way to redirect to the page back after login was attemped, in @login_required pages ?