django-rest-framework

Database first Django models

血红的双手。 提交于 2021-01-27 06:05:30
问题 In ASP.NET there is entity framework or something called code first from database. Is there something similar for Django? I usually work with a pre-existing database that I need to create a backend (and subsequently a front end) for. Some of these RDBs have many tables and relations so manually writing models isn't a good idea. I've scoured Google for solutions but have come up relatively empty handed. Thoughts would be appreciated. Thanks! 回答1: You can use the information on this link.

DRF Serializer readable - writeable non-model field

徘徊边缘 提交于 2021-01-27 05:53:38
问题 On a project with Django / DRF; I have the following model structure: class City(models.Model): name = models.CharField(max_length=100) class Company(models.Model): city = models.ForeignKey(City) . . And following serializer structure for Company model: class CompanySerializer(serializers.ModelSerializer): city_name = serializers.CharField(write_only=True) . . class Meta: model = Company fields = ('city_name',) def create(self, validated_data): # Get city city_name = validated_data.pop('city

Django Rest Framework Multiple Nested Writable Serializers

杀马特。学长 韩版系。学妹 提交于 2021-01-27 05:31:05
问题 I am trying to implement multiple nested writable serializers using django rest framework. I have read the docs available http://www.django-rest-framework.org/api-guide/serializers/#writable-nested-representations I have been able to do this for one level nests but have a problem when there are multiple nests. For example, I have these 3 serializers: class FarmerSerializer(serializers.ModelSerializer): dob = serializers.DateField(write_only=True) gender = serializers.CharField(write_only=True

Django Rest Framework Multiple Nested Writable Serializers

旧街凉风 提交于 2021-01-27 05:31:01
问题 I am trying to implement multiple nested writable serializers using django rest framework. I have read the docs available http://www.django-rest-framework.org/api-guide/serializers/#writable-nested-representations I have been able to do this for one level nests but have a problem when there are multiple nests. For example, I have these 3 serializers: class FarmerSerializer(serializers.ModelSerializer): dob = serializers.DateField(write_only=True) gender = serializers.CharField(write_only=True

HEAD method not allowed after upgrading to django-rest-framework 3.5.3

只愿长相守 提交于 2021-01-27 05:00:32
问题 We are upgrading django-rest-framework from 3.1.3 to 3.5.3. After the upgrade all of our ModelViewSet and viewsets.GenericViewSet views that utilize DefaultRouter to generate the urls no longer allow HEAD method calls. I've searched through the release notes and docs and haven't been able to find any setting or change that caused HEAD to stop being allowed. I'm able to resolve this issue by subclassing the DefaultRouter and altering the route defaults, but I don't think this is the best or

HEAD method not allowed after upgrading to django-rest-framework 3.5.3

拥有回忆 提交于 2021-01-27 04:59:07
问题 We are upgrading django-rest-framework from 3.1.3 to 3.5.3. After the upgrade all of our ModelViewSet and viewsets.GenericViewSet views that utilize DefaultRouter to generate the urls no longer allow HEAD method calls. I've searched through the release notes and docs and haven't been able to find any setting or change that caused HEAD to stop being allowed. I'm able to resolve this issue by subclassing the DefaultRouter and altering the route defaults, but I don't think this is the best or

'CityListViewSet' should either include a `serializer_class` attribute, or override the `get_serializer_class()` method

我与影子孤独终老i 提交于 2021-01-27 04:29:06
问题 I am assuming by the error in the title, once more here for clarity 'CityListViewSet' should either include a `serializer_class` attribute, or override the `get_serializer_class()` method. that my serializer isn't connected to my view, which in my code it should be. I'm not really sure where the bug is in this one. I wonder if any of you have seen something similar? Here is the code. Router: router.register(r'city-list', CityListViewSet, base_name='city-list') view: class CityListViewSet

Request object has no attribute “accepted_renderer”

岁酱吖の 提交于 2021-01-27 03:51:00
问题 What happens if this problem occurs? Request object has no attribute "accepted_renderer" These messages were in my log. There was error encountered while processing this event. Discarded invalid value for parameter 'timestamp' Expand base viewset class: class BaseViewSet(LoggingMixin, viewsets.ModelViewSet): def __init__(self, *args, **kwargs): super(BaseViewSet, self).__init__(**kwargs) authentication_classes = (JSONWebTokenAuthentication, SessionAuthentication, BasicAuthentication)

Request object has no attribute “accepted_renderer”

主宰稳场 提交于 2021-01-27 03:50:24
问题 What happens if this problem occurs? Request object has no attribute "accepted_renderer" These messages were in my log. There was error encountered while processing this event. Discarded invalid value for parameter 'timestamp' Expand base viewset class: class BaseViewSet(LoggingMixin, viewsets.ModelViewSet): def __init__(self, *args, **kwargs): super(BaseViewSet, self).__init__(**kwargs) authentication_classes = (JSONWebTokenAuthentication, SessionAuthentication, BasicAuthentication)

Django Rest Framework with easy-thumbnails

家住魔仙堡 提交于 2021-01-26 14:47:10
问题 With a normal ImageField, serializing the URL is simply image = serializers.ImageField() . What should it look like when using easy-thumbnails? So far, I've only found a function for getting the URL: Django easy_thumbnails accessing image URLs Using this in a serializer would require a SerializerMethodField, which is an unsatisfying solution. I'm looking for a solution that's as efficient/performant as practical, and on one line. 回答1: Best solution is probably to subclass serializers