logo
down
shadow

Django Rest Framework with either a slug or a pk lookup field for the DetailAPIView


Django Rest Framework with either a slug or a pk lookup field for the DetailAPIView

Content Index :

Django Rest Framework with either a slug or a pk lookup field for the DetailAPIView
Tag : python , By : TheMoo
Date : November 26 2020, 03:01 PM

I hope this helps . First: Your urls.py works with the first matched url. So it can not find your second url.
Second: In my opinion you should either stick to the "pk" Version (which is what REST states) or the slug version for the lookup. So in general i would anticipate the process of either looking for a pk or a slug.

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

django-rest-framework PUT rewriting read-only slug field


Tag : development , By : Janne Laine
Date : March 29 2020, 07:55 AM
I wish this help you The pk and/or slug are set in the pre_save method because they're implicit in the URL. (As opposed to the request data, which is handled by the serializer.)
If you really need to change the behavior you can do so by overriding the pre_save method, although it's not obvious to me why you need it to do something different.

Tag : python , By : turret
Date : November 15 2020, 04:01 AM
I hope this helps you . I think you need a HyperlinkedRelatedField, something like this:
class AlbumSerializer(serializers.ModelSerializer):
    class Meta:
        model = proxies.AlbumProxy
        fields = (
            'id', 
            'name', 
            'description', 
            'company', 
            'access_code',  
            'photos'
        )

    photos = serializers.HyperlinkedRelatedField(
        many=True, 
        view_name='<your-photos-view-name>', 
        read_only=True
    )

Slug Field in Django Rest Framework


Tag : django , By : Paul Schwarz
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further There is the django.utils.text.slugify method. If you want to use it you can simple call slugify() on your title. In a serializer you might want to use it like so:
from django.utils.text import slugify

class ExampleSerializer(serializers.ModelSerializer):
    title_slug = serializers.SerializerMethodField()

    def get_title_slug(self, instance):
        return slugify(instance.title)

    class Meta:
        model = Example
        fields = ("title_slug", )

django rest framework access item by lookup field instead of pk 3.4 DRF


Tag : django , By : Mark W
Date : March 29 2020, 07:55 AM

Can email field be used as a lookup field with django rest framework


Tag : django , By : Matt
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further Can an email field in the model be used as a lookup field for the rest api? , specify the lookup_value_regex attribute in the viewset
class FooViewset(ModelViewSet):
    queryset = Foo.objects.all()
    serializer_class = FooSerializer
    lookup_field = 'email'
    lookup_url_kwarg = 'email'
    lookup_value_regex = '[\w@.]+' # here is the new attribute
Related Posts Related QUESTIONS :
  • about backpropagation deep neural network in tensorflow
  • Sort strings in pandas
  • How do access my flask app hosted in docker?
  • Replace the sentence include some text with Python regex
  • Counting the most common element in a 2D List in Python
  • logout a user from the system using a function in python
  • mp4 metadata not found but exists
  • Django: QuerySet with ExpressionWrapper
  • Pandas string search in list of dicts
  • Decryption from RSA encrypted string from sqlite is not the same
  • need of maximum value in int
  • a list of several tuples, how to extract the same of the first two elements in the small tuple in the large tuple
  • Display image of 2D Sinewaves in 3D
  • how to prevent a for loop from overwriting a dictionary?
  • How To Fix: RuntimeError: size mismatch in pyTorch
  • Concatenating two Pandas DataFrames while maintaining index order
  • Why does this not run into an infinite loop?
  • Python Multithreading no current event loop
  • Element Tree - Seaching for specific element value without looping
  • Ignore Nulls in pandas map dictionary
  • How do I get scrap data from web pages using beautifulsoup in python
  • Variable used, golobal or local?
  • I have a regex statement to pull all numbers out of a text file, but it only finds 77 out of the 81 numbers in the file
  • How do I create a dataframe of jobs and companies that includes hyperlinks?
  • Detect if user has clicked the 'maximized' button
  • Does flask_login automatically set the "next" argument?
  • Indents in python 3
  • How to create a pool of threads
  • Pandas giving IndexError on one dataframe but not on another similar dataframe
  • Django Rest Framework - Testing client.login doesn't login user, ret anonymous user
  • Running dag without dag file in airflow
  • Filling across a specified dimension of a numpy array
  • Python populating dataframe in pandas from text files
  • How to interpolate a single ("non-piecewise") cubic spline from a set of data points?
  • Divide 2 integers (leetcode 29) - recursion issue
  • Can someone explain why do I get this output in Python?
  • How do I scrape pdf and html from search results without obvious url
  • Is there a way to automatically make a "collage" of plots with matplotlib?
  • How to combine multiple rows in pandas with shared column values
  • How do I get LOAD_CLASSDEREF instruction after dis.dis?
  • Django - How to add items to Bootstrap dropdown?
  • Linear Regression - Does the below implementation of ridge regression finding coefficient term using gradient method is
  • How to drop all rows in pandas dataframe with negative values?
  • Most Efficient Way to Find Closest Date Between 2 Dataframes
  • Execution error when Passing arguments to a python script using os.system. The script takes sys.argv arguments
  • Looping through a function
  • Create a plot for each unique ID
  • a thread python with 'while' got another thread never start
  • Solution from SciPy solve_ivp contains oscillations for a system of first-order ODEs
  • trigger python events driven by selenium controlled browser
  • Passing line-edits to a contextmanager to set validators
  • Python: globals().items() iterations try to change a dict
  • Is it possible to specify starting values for each parameter (instead of bounds) for scipy's differential evolution?
  • why datetime.now() and constructed datetime using all fields(like year,month...) of now has big timedelta?
  • MySQL multiple table UPDATE query using sqlalchemy core?
  • find if a semantic version is superset of of another version python
  • Type checking against dynamically created objects
  • Struggling with simple reverse function
  • Is there a function for finding the midpoint of n points on sklearn.neighbors.NearestNeighbors?
  • How to set max number of tweets to fetch
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com