First of all, you need to get the formatting correct. It's not easy to read
the way it is now, plus how would anyone know if the error you are getting
is because the formatting on your end was a problem that caused your error?
The other thing which is even more important, you need to provide the
P
If you need to change what is in a standard Django HTML form you'll need to
override the form itself. The docs will explain how to do this.
Here's a StackOverflow page that may help.
https://stackoverflow.com/questions/10040442/override-a-form-in-django-admin
On Thu, Dec 29, 2022 at 12:13 PM Pall
I have relatives with the name D'Ambra, they live in New York.
Relating to your question. It is generally the rule under REStFul web
services is to not put everything under one endpoint.
If you need to change versions and have both still active, at least for a
while, the best thing to use is minet
In this part do this:
class JobState(IntEnum):
RECEIVED = 0
PROCESSING = 1
DONE = 2
FAILED = 3
INT_ENUM = {'RECEIVE': RECEIVE, 'PROCESSING': PROCESSING,
'DONE': DONE, 'FAILED': FAILED}
Then use the INT_ENUM in your serializer. This may not work exactly in your
If I'm not mistaken there are two types of incoming data an object or a
dict, but the output type should always be a dictionary.
The `field.get_attribute` method is used to get values from embedded fields
on the serializer.
I override the `to_representation` method all the time because I write
cust
Phil,
The correct, normal, and common ways are not always the same as many people
don't understand that RFCs define the correct way to do things, not a
specific framework like DRF. The quick a dirty way will ALWAYS lead to
issues down the road.
I use format queries also but only when maneuvering a
Hi Phil,
The best way to solve all these issues is to use mime types to
determine the type of return data.
For example application/vnd.{company name}.{endpoint name}+json;ver=1.
In the above you would replace {company name} with your company or
organization name, and {endpoint name} with something
You will have to write your own code to do this.
You can convert an OrderedDict to a standard dict like this value =
dict(OrderedDict(...))
~Carl
On Wed, May 26, 2021 at 5:01 PM Dana Adams wrote:
> This may be more of a Django than Django Rest question - I am new to both
> - but I thought I'd s
First, never use the PK that Django generates as a way to access a record
through an API. These types of PKs are a numeric sequence and can leave
your site open to sequence attacks where an attacker tries a long series of
numbers to access all or many of your records. Use a public ID of some
sort,
I've converted many systems in my life and I have always found it best to
use the old system as a guide and not try to use anything from the old
system at all. Know what it is that you are trying to do, understand what
the inputs and outputs are, and write new code. The old system would
therefore b
Look at the DRF documentation.
https://www.django-rest-framework.org/api-guide/serializers/#writable-nested-representations
On Tue, Oct 27, 2020 at 7:50 PM C G wrote:
> Hello, i have a question regarding writable nested serializers, i have two
> models that are related through a OneToOne relati
You might want to look at the docs for different methods of versioning. The
way you do versioning is directly related to how you will use mime types in
your code.
I personally use the mine type to determine the versions, this allows you
to change the version on any endpoint just by changing the ver
It's always best to read the docs before asking questions here because in
many instances there are many answers to your questions.
Here's a link to the DRF docs for authentication:
https://www.django-rest-framework.org/tutorial/4-authentication-and-permissions/
~Carl
On Wed, Sep 30, 2020 at 2:45
As I said I don't use ViewSets, but if you add in mixins that cause the
signature of the ViewSet to change it cannot easily and automatically
generate schemas--at least this is my understanding.
The mixins are used in generic views and are not generally needed when
defining your own views except un
If you set `http_method_names = ['get']` and the POST is on the same
endpoint it won't allow a POST. You might want to add 'post' to that
variable.
I, myself don't use ViewSets. I tend to use generic Views. In your case
the ListCreateAPIView generic view in this case. You can find it at
https://www
You may have to override the UniqueTogetherValidator to use the correct
field.
https://www.django-rest-framework.org/api-guide/validators/#uniquetogethervalidator
~Carl
On Fri, Sep 11, 2020 at 3:25 PM Michael Goffioul
wrote:
> I have the following model:
>
> class UnitData(models.Model):
>
Please try to format code properly. It is very difficult to read when not
and you will get more responses if the code is readable.
Thanks
On Thu, Sep 10, 2020 at 4:16 AM Ashuosh Mishra
wrote:
> Trying to generate token of custom user but getting above error,
>
> models.py
> class MyUserManager(B
not looking for shortcut,ready to
> learn and and implement.
>
> On Tue 8 Sep, 2020, 22:11 Carl Nobile, wrote:
>
>> The serializers are what I customize the most. You will need to write
>> field validation methods along with custom create and update methods. If
>> you h
ure you write tests on
> your code WILL be broken.
>
> ~Carl
>
> On Tue, Sep 8, 2020 at 12:33 PM Ashutosh Mishra <
> ashutoshmishra...@gmail.com> wrote:
>
>> My bad,means using custom code,,not by serializer
>>
>> On Tue 8 Sep, 2020, 21:56 Carl Nobile, wro
20 at 12:33 PM Ashutosh Mishra
wrote:
> My bad,means using custom code,,not by serializer
>
> On Tue 8 Sep, 2020, 21:56 Carl Nobile, wrote:
>
>> If you don't want to write ANY custom code then you probably cannot do
>> it. I've never written any site without at
If you don't want to write ANY custom code then you probably cannot do it.
I've never written any site without at least some custom code.
At a minimum, you will probably need some custom permission classes that
you would set on the views--this keeps people with different roles out of
stuff they sho
You need to at least describe the issues you are having. The mimetype you
are using etc.
On Sat, Aug 29, 2020 at 1:00 AM yashwanth balanagu <
balanaguyashwa...@gmail.com> wrote:
> I got it atlast i am storting the images in server side instead of storing
> in cloud storage so i got mistake there
It depends on the type of token you user JWT (JSON Web Token) are the most
comment types to use when needed additional user details, however, you must
be using OAuth2 to use these. DRF \'s internal token system cannot use JWT
tokens.
On Sat, Aug 29, 2020 at 12:58 AM yashwanth balanagu <
balanaguy
So the url() function is deprecated you should use re_path() if you need to
use regex.
from django.urls import path, re_path
~Carl
On Sat, Aug 8, 2020 at 12:32 PM Wanderley S wrote:
> Hi again Daniel.
> You made your point, I don't agree with you though.
> Seems to me that the documentation i
You can use the source argument in a serializer field.
https://www.django-rest-framework.org/api-guide/fields/#source
inventory_type_public_id = serializers.CharField(
source='inventory_type.public_id', required=False)
In the above example `inventory_type_public_id` becomes the new field name
two inputs, but I don't understand why DRF outputs it as a string.
>
> Eric
>
> On Fri, Jul 17, 2020 at 9:34 AM Carl Nobile wrote:
>
>> So I see one issue, but first, is this supposed to be a JSON object?
>> If so it will not p
ngeField.
>
> "years_produced": "{\"bounds\": \"[)\", \"lower\": \"1935\", \"upper\":
> \"1946\"}",
>
> Baze, did you ever get to the bottom of your issues or, Carl, do you have
> any insights as to wha
What @Brent said is basically correct, however, it will fail if you have
model mixins that change fields. That's because the field will not be
changed until after the full_clean() method is called.
So how to fix this? It's not too difficult. I create a mixin that just does
the full_clean() as in th
Brent, overriding the 'to_internal_value' method is normal and encouraged,
however, the 'run_validation' shouldn't generally be overridden, what you
can override is the 'validate' method which is called by 'run_validation'.
~Carl
On Tue, Jun 30, 2020 at 5:51 PM Brent O'Connor wrote:
> For anyone
sure that valid
> numbers, etc. are being sent to the API.
>
> On Sat, Jun 27, 2020 at 12:25 PM Carl Nobile
> wrote:
>
>> It is possible to turn off the built infield errors. The empty list
>> essentially turns off al field validation. If there are multiple and you
>> do
It is possible to turn off the built infield errors. The empty list
essentially turns off al field validation. If there are multiple and you
don't want all turned off you would need to specify them yourself.
Class SomeSeializer(...):
class Meta:
extra_kwargs = {
'field_name
I realize that this is just my opinion, however, I've been writing code for
over 40 years and Python for over 20.
There is nothing, no process, not a special package that will develop good
code for you, only well-trained engineers that follow best practices.
In Python, this means the coding standar
i mamatha
> Date: Fri, 1 May 2020, 9:27 pm
> Subject: Re: Error: User permissions
> To:
>
>
>
> On Fri, 1 May 2020, 8:46 pm Carl Nobile, wrote:
>
>> You would get this if you ran the command from a restricted directory.
>> You gave no details, so I cannot real
You would get this if you ran the command from a restricted directory.
You gave no details, so I cannot really say much more than this.
Are you using pip? Show the actual screen dump.
On Thu, Apr 30, 2020 at 9:46 PM sathri mamatha
wrote:
> Please tell me the solution for this ERROR
>
> Error
It looks like you are, for some reason, returning a dump of the objects on
the model, not the data. Something is messed up in your code. You might
want to post the sterilizer *create* and *update* methods you created.
On Wed, Apr 29, 2020 at 11:50 AM Nazish Akhtar
wrote:
> While saving serialize
You asked a very basic question and the answer, in all cases, is yes. You
need to RTM (https://www.django-rest-framework.org/), it's all in there.
On Wed, Apr 22, 2020 at 10:44 AM Linovia wrote:
> Hi,
>
> If you are referring to the browsable API, you should see a DELETE request.
> If you are u
Usually the schema in your links will reflect the schema used on the site.
It looks like your running locally in a development environment, when you
go to a production site the schema should change, assuming you use TSL in
production.
You may be able to force it while developing, but I see no reaso
You may be misunderstanding what the IsAuthenticated really does. All users
that have an account in the Django application have this set to True
weather or not they are logged in. So it doesn't indicate that a person is
actually logged in or not. You will need to use other means to ensure that
only
As a side note never put credentials in the body of a JSON request, this is
considered to be a security risk as anything in the body can be logged. Use
one of the methods that are described here
https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication.
Basic authentication is the most commo
or your comment, however.
~Carl
On Tue, Dec 10, 2019 at 2:06 AM José Manuel Valdivia Romero <
josevaldiviarom...@gmail.com> wrote:
> Hi Carl,
>
> I think you are using the wrong header in your request, try to use:
> "Content-Type": "application/json"
>
&g
It seems that you have both the
serializer_class
member object and the
get_serializer_class
method set. Remove the
serializer_class.
On Thursday, November 21, 2019 at 8:21:44 PM UTC-5, Cristian Benavides
Jimenez wrote:
>
> Hi everybody,
>
> I try use a two serializers in one view inherits
The request.user.is_authenticated() is always true unless the requester is
the Annonymous user.
Are you sure you logged in and that you are the requester before looking at
that value?
On Thursday, November 28, 2019 at 8:26:29 AM UTC-5, Eric Gustavsson wrote:
>
> Hey,
>
> I've setup mozilla-djan
I'm trying to run my unit tests using JSON however I'm getting this error:
{'detail': ErrorDetail(string='XML parse error - not well-formed (invalid
token): line 1, column 0', code='parse_error')}
My settings are:
REST_FRAMEWORK = {
...
'DEFAULT_PARSER_CLASSES': (
'rest_framewo
I do async all the time with DRF, sometimes I have DB connection issues,
but for the most part it all works fine.
On Fri, Nov 22, 2019 at 8:12 AM Xavier Ordoquy wrote:
> What about it ?
> I don’t think DRF we use anything that is async incompatible outside
> Django itself.
>
> Regards,
> Xavier
Sajan, It's best to just follow the documentation on the DRF site
https://www.django-rest-framework.org/.
The Django admin is very easy to set up and sometimes is a necessity. Just
look at the Django docs.
On Sat, Nov 2, 2019 at 12:58 PM Sajan s wrote:
> any sample url?
>
> On Saturday, November
Kęstutis, there are three ways to do this, in order of preference below.
1. Use a different generic view make *RetrieveUpdateAPIView.*
2. Set, at the class level in your view this class member object:
http_method_names
= ['get', 'head', 'options',]. This will give you only the methods yo
You must set media type for all your endpoints or they will default to DRF
mime types.
On Fri, Sep 20, 2019 at 11:08 AM göktürk sığırtmaç
wrote:
> While i'm overriding post method from generics.ListCreateAPIView i have
> error unsupported media type but i don't send media.
>
> Serializer file:
nywhere we can read about all this permissions you have set up?
>
> They look very interesting, and I have to learn more about and how to use
> them.
>
> Best regards!
>
> El sáb., 24 ago. 2019 a las 4:57, Carl Nobile ()
> escribió:
>
>> You should use the p
First off NEVER EVER put credentials in the body of a request. This
introduces a serious security hole (bodies get logged and the creds will be
in the log). Use the Authorization header and Basic auth then always use
HTTPS (TLS). *Authorization: Basic * See
https://en.wikipedia.org/wiki/Basic_acces
First, I see at least one syntax error in your code.
*fields = ('__all__')* should be *fields = '__all__'.* Although what you
have may work, it looks like you're trying to use a tuple which it isn't.
The model field *BinaryField* is, under the covers, a *CharField* with a
little extra code around
The BoleanField is by definition a binary field if you're only looking for
a 0 and 1.
You could also override the DecimalField and make it do what you want.
~Carl
On Wed, Sep 11, 2019 at 6:35 AM Jaco wrote:
> Hi,
>
> as BinaryField seems not supported by Django REST framework (out of the
> box)
You should use the permission structure setup within DRF. First, get the
`rest_conditions` package. This package will let you use AND, OR etc with
permissions. I wrote a lot of my own permissions also. MOF, a lot of the
imports you see are custom.
For example:
from rest_framework.permissions imp
Are you talking about incoming data? If so you should be sending ISO aware
date-time objects as such: 2019-05-12T16:27:34.503919-04:00
If you are talking about outgoing data then you should be saving in the DB
aware UTC date-times as python datetime objects.
DRF will always do the right thing if yo
Humm, I've never had this issue. Have you set up the permissions on the
views correctly?
It's kind of difficult making definitive statements about this without
seeing code.
On Thu, Aug 15, 2019 at 10:38 AM göktürk sığırtmaç
wrote:
> I was login (/admin) in my app. Later when I want to access pro
Well, this is a Django REST Framework group, so you're not going to find a
lot of Flask help here.
With that said, yes this should be possible in any framework, your biggest
problem is going to be how long it takes to process the file. If it takes
much longer than several seconds you will need
I can see a few issues here.
1. You defined *'strt_day'* and *'end_day'* inside the *Meta* class, you
cannot do this. It won't work correctly.
2. If you actually get back a real PK from the DB then the DB at least
thinks it got created.
Are you sure it didn't fail for some other rea
Hi Kyle,
I'm thinking you will have reentrant issues, in other words, a single
instance of a serializer will not be thread/process safe. If you
*dir(instance)* you will see a whole lot of member objects that will be
instance-specific data. Django is pretty good at handling multiple
instances o
Clara,
This is something that the DRF (Django Rest Framework) serializers should
do auto-magically. What I'm thinking is that you do not have the correct
settings in your settings file. I should be set to something like this:
REST_FRAMEWORK = {
'DEFAULT_PARSER_CLASSES': (
'rest_fram
58 matches
Mail list logo