django-rest-framework

Implement roles in django rest framework

六眼飞鱼酱① 提交于 2020-05-11 22:01:36
问题 I am building an API that should have the following kind of users super_user - create/manage admins admin - manage events(model) and event participants participants - participate in events, invited to events by admins Additional i want to have each type of user to have phone number field I tried class SuperUser(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) phone_number = models.CharField(max_length=20) class Admin(models.Model): user = models.OneToOneField(User,

Implement roles in django rest framework

大城市里の小女人 提交于 2020-05-11 22:01:23
问题 I am building an API that should have the following kind of users super_user - create/manage admins admin - manage events(model) and event participants participants - participate in events, invited to events by admins Additional i want to have each type of user to have phone number field I tried class SuperUser(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) phone_number = models.CharField(max_length=20) class Admin(models.Model): user = models.OneToOneField(User,

This QueryDict instance is immutable

一笑奈何 提交于 2020-05-10 04:25:39
问题 I have a Branch model with a foreign key to account (the owner of the branch): class Branch(SafeDeleteModel): _safedelete_policy = SOFT_DELETE_CASCADE name = models.CharField(max_length=100) account = models.ForeignKey(Account, null=True, on_delete=models.CASCADE) location = models.TextField() phone = models.CharField(max_length=20, blank=True, null=True, default=None) create_at = models.DateTimeField(auto_now_add=True, null=True) update_at = models.DateTimeField(auto_now=True, null=True) def

When are create and update called in djangorestframework serializer?

試著忘記壹切 提交于 2020-05-09 17:54:17
问题 I'm currently implementing djangorestframework for my app RESTful API. After playing around with it, I still do not clearly understand what .create(self, validated_data) and .update(self, validated_data) used for in the serializer. As I understand, CRUD only calls the 4 main methods in viewsets.ModelViewSet : create() , retrive() , update() , and destroy() . I also have already tried to debug and print out stuff to see when the .create() and .update() methods are called in both ModelViewSet

Using Django-taggit and django-taggit-serializer with issue

ぐ巨炮叔叔 提交于 2020-04-30 09:31:53
问题 I am trying to add tags in my model by taggit and taggit serializer. I making my API in rest framework. I followed the instruction(https://github.com/glemmaPaul/django-taggit-serializer) but it is still an issues: "tags": [ "Invalid json list. A tag list submitted in string form must be valid json."] /setting.py INSTALLED_APPS = [ [...] 'rest_framework', 'taggit', 'taggit_serializer', ] /models.py tags = TaggableManager(blank = True) /serializer.py class JobSerializer(TaggitSerializer

Using Django-taggit and django-taggit-serializer with issue

半城伤御伤魂 提交于 2020-04-30 09:31:14
问题 I am trying to add tags in my model by taggit and taggit serializer. I making my API in rest framework. I followed the instruction(https://github.com/glemmaPaul/django-taggit-serializer) but it is still an issues: "tags": [ "Invalid json list. A tag list submitted in string form must be valid json."] /setting.py INSTALLED_APPS = [ [...] 'rest_framework', 'taggit', 'taggit_serializer', ] /models.py tags = TaggableManager(blank = True) /serializer.py class JobSerializer(TaggitSerializer

Passing Trait Value to SubFactory Django

半腔热情 提交于 2020-04-30 09:28:08
问题 I have two factories. class DispatchDataFactory(factory.django.DjangoModelFactory): class Meta: model = models.DispatchData order = factory.SelfAttribute('order_data.order') sku = factory.LazyAttribute(lambda obj: '%d' % obj.order_data.sku) category = SKUCategory.SINGLE quantity = 50 class Params: combo_sku=False order_data = factory.SubFactory(OrderDataFactory, combo_sku=factory.SelfAttribute('combo_sku')) combo_sku = factory.Trait( sku=factory.LazyAttribute(lambda obj: '%d' % obj.order_data

DRF password rest workflow throwing django.template.exceptions.TemplateDoesNotExist

╄→гoц情女王★ 提交于 2020-04-30 06:32:38
问题 I'm using Django Rest Password Reset for the reset password workflow as it's, at my sight, the best supported for this particular case. In urls.py # Password reset path('reset-password/verify-token/', views.CustomPasswordTokenVerificationView.as_view(), name='password_reset_verify_token'), path('reset-password/', include('django_rest_passwordreset.urls', namespace='password_reset')), and in settings.py EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' If i go to reset-password/

Uploading multiple images and nested json using multipart/form-data in Django REST Framework

ε祈祈猫儿з 提交于 2020-04-28 11:02:14
问题 I have a problem with parsing request.data in viewset. I have a model that can add multiple images depending on a product. I want to split the image from the incoming data, send product data to ProductSerializer, and after that send image to its serializer with product data and save it. I have two model, simply like this: def Product(models.Model): name = models.CharField(max_length=20) color = models.ForeignKey(Color, on_delete=models.CASCADE) def Color(models.Model): name = models.CharField

Uploading multiple images and nested json using multipart/form-data in Django REST Framework

微笑、不失礼 提交于 2020-04-28 11:02:11
问题 I have a problem with parsing request.data in viewset. I have a model that can add multiple images depending on a product. I want to split the image from the incoming data, send product data to ProductSerializer, and after that send image to its serializer with product data and save it. I have two model, simply like this: def Product(models.Model): name = models.CharField(max_length=20) color = models.ForeignKey(Color, on_delete=models.CASCADE) def Color(models.Model): name = models.CharField