Re: Nested fields error: Write an explicit update() method, but there is already one?

2023-10-31 Thread Carl Nobile
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

Re: Which Python file renders textarea.html and forms.html ?

2022-12-29 Thread Carl Nobile
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

Re: Invoking views directly

2022-11-17 Thread Carl Nobile
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

Re: ModelSerializers & schema generation

2021-08-21 Thread Carl Nobile
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

Re: Field to_representation function seems to have inconsistent arguments

2021-07-07 Thread Carl Nobile
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

Re: Requiring format extension on all URLs

2021-06-22 Thread Carl Nobile
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

Re: Requiring format extension on all URLs

2021-06-21 Thread Carl Nobile
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

Re: Question about combining the results of two serializers

2021-05-26 Thread Carl Nobile
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

Re: Updating foreign key

2021-01-03 Thread Carl Nobile
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,

Re: How to convert Stored procedure logic to Django rest framework

2020-11-15 Thread Carl Nobile
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

Re: How to deal with nested serializers and form data

2020-10-27 Thread Carl Nobile
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

Re: Limit content-types in request body?

2020-10-11 Thread Carl Nobile
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

Re: How to make my own model authentication and authorizations in Django Rest Framework

2020-09-30 Thread Carl Nobile
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

Re: action methods is not allowed to have more methods rather than their viewsets

2020-09-30 Thread Carl Nobile
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

Re: action methods is not allowed to have more methods rather than their viewsets

2020-09-29 Thread Carl Nobile
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

Re: Problem with unique_together and field override in ModelSerializer

2020-09-11 Thread Carl Nobile
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): >

Re: message": "Cannot query \"\": Must be \"User\" instance.",

2020-09-10 Thread Carl Nobile
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

Re: Custom user model

2020-09-08 Thread Carl Nobile
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

Re: Custom user model

2020-09-08 Thread Carl Nobile
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

Re: Custom user model

2020-09-08 Thread Carl Nobile
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

Re: Custom user model

2020-09-08 Thread Carl Nobile
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

Re: I am facing issues in django with images can any one help me... to sort it out

2020-08-30 Thread Carl Nobile
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

Re: How can i get user login details from auth token is it possible

2020-08-30 Thread Carl Nobile
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

Re: Reality Check for (problematic?) DRF Installation Instructions

2020-08-08 Thread Carl Nobile
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

Re: How to rename field?

2020-07-26 Thread Carl Nobile
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

Re: Unusual default serialization for DateRangeField (django.contrib.postgres.fields.DateRangeField)

2020-07-17 Thread Carl Nobile
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

Re: Unusual default serialization for DateRangeField (django.contrib.postgres.fields.DateRangeField)

2020-07-17 Thread Carl Nobile
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

Re: Sharing validation with the admin under DRF 3

2020-07-06 Thread Carl Nobile
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

Re: Django Rest Framework Validation Order Issue

2020-06-30 Thread Carl Nobile
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

Re: Django Rest Framework Validation Order Issue

2020-06-27 Thread Carl Nobile
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

Re: Django Rest Framework Validation Order Issue

2020-06-27 Thread Carl Nobile
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

Re: Behaviour driven development in Django rest framework.

2020-05-03 Thread Carl Nobile
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

Re: Error: User permissions

2020-05-01 Thread Carl Nobile
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

Re: Error: User permissions

2020-05-01 Thread Carl Nobile
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

Re: serializer save returns ​ DoesNotExis, MultipleObjectsReturned

2020-04-29 Thread Carl Nobile
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

Re: Is it possible to send HTTP DELETE or PATCH from DRF web page with a web browser ?

2020-04-22 Thread Carl Nobile
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

Re: HTTPS resource links in DRF

2020-02-01 Thread Carl Nobile
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

Re: setting the default authentication to IsAuthenticated in settings.py globally

2020-01-08 Thread Carl Nobile
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

Re: Upload image on json

2020-01-05 Thread Carl Nobile
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

Re: While running unit tests the wrong parser is being used.

2019-12-11 Thread Carl Nobile
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

Re: get_serializer_class don't work in GenericViewSet

2019-11-30 Thread Carl Nobile
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

Re: is_authenticated returns false in DRF, true outside DRF

2019-11-30 Thread Carl Nobile
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

While running unit tests the wrong parser is being used.

2019-11-30 Thread Carl Nobile
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

Re: Django is getting ASYNC, what about DRF ?

2019-11-22 Thread Carl Nobile
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

Re: Is possible to create Django Rest API without admin module ?

2019-11-02 Thread Carl Nobile
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

Re: Delete method

2019-09-25 Thread Carl Nobile
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

Re: Unsupported Media Type

2019-09-20 Thread Carl Nobile
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:

Re: Redirect

2019-09-12 Thread Carl Nobile
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

Re: RegisterSerializer doesn't recognize data from rest-auth/registration API, except for email data.

2019-09-12 Thread Carl Nobile
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

Re: models.BinaryField, does not work easy as other fields

2019-09-11 Thread Carl Nobile
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

Re: BinaryField

2019-09-11 Thread Carl Nobile
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)

Re: Redirect

2019-08-23 Thread Carl Nobile
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

Re: Unusual default serialization for DateRangeField (django.contrib.postgres.fields.DateRangeField)

2019-08-15 Thread Carl Nobile
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

Re: Auth

2019-08-15 Thread Carl Nobile
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

Re: Image file upload - process - download

2019-05-27 Thread Carl Nobile
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

Re: .save() method returning an saved instance of object but object creation does not take place in DB

2019-05-27 Thread Carl Nobile
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

Re: ThreadedListSerializer - will this cause me any problems?

2019-05-27 Thread Carl Nobile
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

Re: PrimaryKeyRelatedField from property method serialization

2019-05-27 Thread Carl Nobile
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