I am trying to run a model (that i have saved already) inside my django project and i dont know how this is to be done . I simply searched web for this problem and came across this
https://stefanbschneider.github.io/blog/pytorch-django
Here, this guy imports a densenet and json but in my case i already have a running model and there are only 2 classes that is ant and bees
Can anybody help me with this? what i did try is i cloned the project and replaced with the preloaded model with my model and skipped the json and added my classes but nothing seems to work
Related
I know the question has already been asked several times, but nothing worked for me
I have a project that works properly locally, but when I deployed it on a virtual machine (working with CentOS), many problems related to the database appeared.
When I try to print the fields of my 'Project' model from the shell, they are displayed correctly, but I can't display any object from this model :
Same error when I try to create a Project object :
This happens only with the models of my 'projects' application, I have another application who works correctly
I removed all my migrations files and run makemigrations and migrate, nothing changed.
If someone can give me any suggestion, I'm interested (nothing important in the database, I can reset it if necessary)
Don't hesitate to tell me if you need me to add infomrations to my post
I am going to extend the django user models - is it best practice to create a new models.py in my project directory: I.e:
project
application
migrations
static
models.py (all my application specific models)
project
forms.py
urls.py
views.py
*** project models.py ? ***
I want to add email confirmation to my user sign up. So basically just extend the user model. I am thinking this may not be best practice to do in my application models, but for this case it is only going to be one model so would not really matter. However if I want to extend more non-application specific models then it might be better to do this in a separate file?
Does anyone do anything similar and have any tips? Thanks
I don't think putting model inside the project is a food idea, but its practical possible.
For your case I would create an app called utils and put those models there. In real sense i don't think there is non-app specific model . . . correct me if I am wrong.
Plus you can have as many apps as you want
Also you can check post for more
I'm working on a web page which uses Django-quiz app. When you install the django-quiz, you can create quizes, questions etc. in Admin.
Unfortunately, there is no way, how to assign Quiz to my model Language so I'm looking for a way, how to add field Language into the model Quiz.
I've tried this but it does not work. I've tried already to create a proxy model with additional field but I realised that it is not possible in proxy models.
from quiz.models import Sitting,Quiz
class QuizAddLanguage(models.Model):
quiz = models.OneToOneField(Quiz)
language = models.ForeignKey(Language)
Do you know what to do to add field to third party app model?
For this time, OneToOne should be enough - for each language there will be one quiz
Since its one to one then you can just define the relationship on your own language class, django by default, will provide you the reverse lookup meaning
language_obj.quiz
quiz_obj.language
will both be valid.
Here is a relevant Django ticket, which was closed with a resolution of "wontfix" six years ago:
https://code.djangoproject.com/ticket/14969
I think this comment provides some good information:
Comments gives you the *right* way to handle this problem -- you define an interface, and make the model itself pluggable. Not all Django's contrib apps follow this approach, but that doesn't mean we bake monkeypatching into the core -- we fix the contrib apps.
django.contrib.comments is now a standalone app, but it still makes itself relatively easy to customize. Here is the relevant documentation:
https://django-contrib-comments.readthedocs.io/en/latest/custom.html
If a third party app doesn't make itself easy to customize, I would suggest asking the developer to update it and point them to the above links for examples on how to go about doing it.
I'm creating a GUI for creating/editing models within the admin interface, see Github project. When a person creates a new app I want that app automatically added to the admin interface and any models in that app. How do I automatically do that?
You can do a source code editor, maybe based on django-alto which already has edition for view code, or do a ModelModel that is loaded dynamically in which case you might want to base on django-not-eav.
The advantage of django-not-eav's approach is that it should be easier to use than source code editing for the average webmaster/website admin.
Either way, it's going to be quite some work :)
I am thinking of creating some subclassed Django model fields and distributing them as a package on PyPI. I like to write unit tests for my code (à la TDD), but I'm a bit puzzled as to how I'd write tests for this particular library.
The first thought that came to my mind was to create a Django project that makes use of my subclasses and just use the Django test tools, but that doesn't seem very elegant at all. There's got to be a better way!
Is there a method of somehow bootstrapping Django for this type of thing? I'd appreciate someone pointing me in the right direction. Thanks!
Django itself comes with some tests for field-subclassing; the tests have their own models.py where the custom fields are used. You should get the best impression when you have a look at the actual code yourself!
Addition: To have the models defined in your test package being discovered by django you will have to add your yourapp.test package to INSTALLED_APPS.
Django itself has a built-in mechanism for its own tests to be automatically discovered and added to INSTALLED_APPS.