Whats difference between models.py & forms.py? [closed] - python

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I am learning about Django & Python from past two weeks.though, my reading i came across models.py & forms.py. structure of both this is almost same. can anyone explain me whats the difference between them?
I also want to know where do i have to write the (<form> </form>) code. I mean in any html file or *.py file or where?

They are indeed very different in concept, albeit they can look similar. Let me explain:
Models define your business objects and data structures. They are the "entities" of the application wich have to be persisted in the database. Since it's a definition of the objects and their attributes, you define "fields". They represent the data structure and persistence of the app.
Forms are meant to make easier to get input from the user, validate data, render html and recover values supplied by the user. They also have fields but you have to note they don't map to a database and they don't represent an entity. They represent the "inputs" of the app.

Related

How do I generate random jsons from JSchema [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am looking for a way to generate random data for testing purposes (around 10000 files). For this testing I have a json schema.
Generation JSchema:
RunTest(){
JSchemaGenerator generator = new JSchemaGenerator();
JSchema schemaBuilding = generator.Generate(typeof(TestClass));
}
The code itself is in C# so ideally I would have a C# code for doing this, though a python solution is also accaptable. I have found a number of questions on this topic that got websites or only focusses on a single prefixed sample but I can't find how to do this in C# (or less preferably python), anybody got any good way of doing this?
As for the reason for doing this: it's two fold: 1 this tests the stability of the system by entering a lot of random data looking for edge cases we haven't thought of and 2 it's a load test. (so basically a smoke+load test)
In Oxygen Developer there is a tool that allows you to generate random JSON files from a JSON Schema, but you need to do this manually from an interface. The action can be found in the Tools menu and it opens a dialog box where you can configure various options for generating the JSON instances.
You can find more details in the user manual: https://www.oxygenxml.com/doc/versions/23.0/ug-editor/topics/json-schema-instance-generator-2.html

using request.data instead of serializer class in Django [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I have been using in one of my views request.data instead of serialzer to get json data and work on it, my question is this ok or lets say "a good practice" to use request.data or should i create serializer class for that view?
The reason to use a serializer in the first place is to transform native python data types to valid JSON and vice-versa. Consequently, the serializer adds a layer of validation to make sure that this transformation process runs correctly in accordance with your serializer definition.
If you decide to omit the serializer in the views, you would have to handle data validation there yourself and you end up implementing a feature which already exists in practice and has been "battle-tested" and worked on by multiple accomplished developers. There are cases where you don't strictly need a serializer in your views, for example when you simply display data from another source and only allow GET requests, but whenever you deal with data input I would consider it bad practice to not use serializers.

Viewing queries history in django [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I need something to view the queries happened ( creating or updating or deleting ) in DB tables in Django, I want it to be able to be used by the user, not at the admin panel
If I understand your question correctly, you are looking for a model history (sometimes also called "audit trail").
In this link there is a comparisson of different packages that can be used for audit/history of models.
As I already pointed out in this answer,
I use django-simple-history which comes with a nice integration to view the list of changes of every model instance in the admin.
For my use case at least, django-simple-history provided me with what I needed, and so far I did not face any issues with it, even though this package does NOT track history of ManyToManyField (for that see related questions like this or this or the Github issue).
Now, if you want the end user to be able to see the history (but not through the admin panel), then you would need to add a few pages for that.
For example, you could add a list view for each model using djangos generic ListView.

Django: What are the downsides of manually altering model fields with SQL? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
Since syncdb doesn't alter existing tables [1] I'm wondering what the downsides would be of logging in to a database and altering the structure.
More specifically I'd want to know what potential problems could be triggered if I change the length or type of a field (e.g. INT to BIGINT).
Will there be any issues with Django trying to truncate or alter the value to fit within the scope defined in the model?
Downsides ? If you are talking about simple project, then there arent any. Do whatever pleases you :). If the project grows bigger, then read next paragraph :P
If it is larger project and has other contributors (and even if it does not), you need to version control it. And for this reason, manual changes are BAD. Cause you just cant go back to earlier version without changing the database.... BUT....
But since you are talking about doing this manually, i feel, that i need to point out the existance of http://south.aeracode.org/
Which is created exactly for the reason that you, perhaps, should not be doing this manually.
BTW. im trolling here and talking tongue in cheek... don't take this post 100% seriously :P
Django South is the solution to this problem. It is a "must have" app to include (and here I'm going to disagree with #OdifYitsaeb's answer) in ANY project, not just large ones. It is so simple and powerful that you are essentially creating more work for yourself if you don't use it even in a tiny personal project.
It's soon to be included into Django core in (I beleive) 1.7 as well, so it's a good idea to get familiar with it now.

how should I create good rest api? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
to get posts for a user:
GET http://test.com/users/123/posts or GET http://test.com/posts?user_id=123
to get new posts count:
GET http://test.com/posts/count/new or http://test.com/new_posts_count or others?
This is a good read: http://www.vinaysahni.com/best-practices-for-a-pragmatic-restful-api.
And in terms of the two formats you suggested: I prefer the former.
Doesn't matter from a REST point of view (REST doesn't define URI structure). The client should not know the URL structure before hand so technically it doesn't matter to the client either.
I personally prefer the first style as I think it makes more sense when you have a resource hierarchy. It also allows a client to move back up a URI by simply chopping off the end resource, similar to how you can go back up a directory on a file system by simply clicking the parent button.
But there is no "right answer" to this from a REST point of view. REST is concerned with the transfer of state of resources, not the resource hierarchy or URI definition.

Categories