Django: How can i pass user input value from models.py to other file(ex entity_exctraction.py)
I am new to Django so please guide if i am going on wrong way.
Problem Defination:
To take user input AS string and perform various manipulations on the input and save the modified value in the database.I also want to show this modified input as a json response.
For temporary purpose i have created 4 fields namely ticker,open,close,volume.I want to transfer the open value from models.py to entity_exctraction.py file and multiply by 2 and save the updated value to the database.
I tried to write the same logic in the models.py (commented part) and its working fine.but what i want is to write all business logic in some different file.
Models.py
from django.db import models
from .entity_exctraction import Exctraction
class Stock(models.Model):
ticker = models.CharField(max_length=10)
open = models.FloatField()
close = models.FloatField()
volume= models.IntegerField()
open_val = Exctraction.update(open)
#def save(self, force_insert=False, force_update=False, using=None,
# update_fields=None):
# print(self.open)
# self.open = self.open * 2
# super(Stock, self).save()
def __str__(self):
return self.ticker
entity_exctraction.py
from django.db import models
class Exctraction():
def update(val):
val = val * 2.0
return val
serializers.py
from rest_framework import serializers
from .models import Stock
class StockSerializer(serializers.ModelSerializer):
class Meta:
model = Stock
print(type(model))
#model.open=model.open*2
#fields = ('ticker', 'volume')
fields = '__all__'
python json django sqlite3 django-rest-framework
add a comment |
I am new to Django so please guide if i am going on wrong way.
Problem Defination:
To take user input AS string and perform various manipulations on the input and save the modified value in the database.I also want to show this modified input as a json response.
For temporary purpose i have created 4 fields namely ticker,open,close,volume.I want to transfer the open value from models.py to entity_exctraction.py file and multiply by 2 and save the updated value to the database.
I tried to write the same logic in the models.py (commented part) and its working fine.but what i want is to write all business logic in some different file.
Models.py
from django.db import models
from .entity_exctraction import Exctraction
class Stock(models.Model):
ticker = models.CharField(max_length=10)
open = models.FloatField()
close = models.FloatField()
volume= models.IntegerField()
open_val = Exctraction.update(open)
#def save(self, force_insert=False, force_update=False, using=None,
# update_fields=None):
# print(self.open)
# self.open = self.open * 2
# super(Stock, self).save()
def __str__(self):
return self.ticker
entity_exctraction.py
from django.db import models
class Exctraction():
def update(val):
val = val * 2.0
return val
serializers.py
from rest_framework import serializers
from .models import Stock
class StockSerializer(serializers.ModelSerializer):
class Meta:
model = Stock
print(type(model))
#model.open=model.open*2
#fields = ('ticker', 'volume')
fields = '__all__'
python json django sqlite3 django-rest-framework
I can't see why you need an actual Extraction class. Why not just functions in extraction.py?
– Daniel Roseman
Nov 22 '18 at 12:38
@DanielRoseman Actually i want to perform several task (related to natural language processing) on the one user input string. So i want whole bunch of code in separate python file.
– Hiru
Nov 22 '18 at 12:46
@DanielRoseman i also tried writing direct function but now it is giving me error unsupported operant type. As i am passing "open" which is having FloatField type and multiplaying with 2.It is not passing original value to other file.
– Hiru
Nov 22 '18 at 13:05
add a comment |
I am new to Django so please guide if i am going on wrong way.
Problem Defination:
To take user input AS string and perform various manipulations on the input and save the modified value in the database.I also want to show this modified input as a json response.
For temporary purpose i have created 4 fields namely ticker,open,close,volume.I want to transfer the open value from models.py to entity_exctraction.py file and multiply by 2 and save the updated value to the database.
I tried to write the same logic in the models.py (commented part) and its working fine.but what i want is to write all business logic in some different file.
Models.py
from django.db import models
from .entity_exctraction import Exctraction
class Stock(models.Model):
ticker = models.CharField(max_length=10)
open = models.FloatField()
close = models.FloatField()
volume= models.IntegerField()
open_val = Exctraction.update(open)
#def save(self, force_insert=False, force_update=False, using=None,
# update_fields=None):
# print(self.open)
# self.open = self.open * 2
# super(Stock, self).save()
def __str__(self):
return self.ticker
entity_exctraction.py
from django.db import models
class Exctraction():
def update(val):
val = val * 2.0
return val
serializers.py
from rest_framework import serializers
from .models import Stock
class StockSerializer(serializers.ModelSerializer):
class Meta:
model = Stock
print(type(model))
#model.open=model.open*2
#fields = ('ticker', 'volume')
fields = '__all__'
python json django sqlite3 django-rest-framework
I am new to Django so please guide if i am going on wrong way.
Problem Defination:
To take user input AS string and perform various manipulations on the input and save the modified value in the database.I also want to show this modified input as a json response.
For temporary purpose i have created 4 fields namely ticker,open,close,volume.I want to transfer the open value from models.py to entity_exctraction.py file and multiply by 2 and save the updated value to the database.
I tried to write the same logic in the models.py (commented part) and its working fine.but what i want is to write all business logic in some different file.
Models.py
from django.db import models
from .entity_exctraction import Exctraction
class Stock(models.Model):
ticker = models.CharField(max_length=10)
open = models.FloatField()
close = models.FloatField()
volume= models.IntegerField()
open_val = Exctraction.update(open)
#def save(self, force_insert=False, force_update=False, using=None,
# update_fields=None):
# print(self.open)
# self.open = self.open * 2
# super(Stock, self).save()
def __str__(self):
return self.ticker
entity_exctraction.py
from django.db import models
class Exctraction():
def update(val):
val = val * 2.0
return val
serializers.py
from rest_framework import serializers
from .models import Stock
class StockSerializer(serializers.ModelSerializer):
class Meta:
model = Stock
print(type(model))
#model.open=model.open*2
#fields = ('ticker', 'volume')
fields = '__all__'
python json django sqlite3 django-rest-framework
python json django sqlite3 django-rest-framework
edited Nov 22 '18 at 12:26
Hiru
asked Nov 22 '18 at 12:20


HiruHiru
98711329
98711329
I can't see why you need an actual Extraction class. Why not just functions in extraction.py?
– Daniel Roseman
Nov 22 '18 at 12:38
@DanielRoseman Actually i want to perform several task (related to natural language processing) on the one user input string. So i want whole bunch of code in separate python file.
– Hiru
Nov 22 '18 at 12:46
@DanielRoseman i also tried writing direct function but now it is giving me error unsupported operant type. As i am passing "open" which is having FloatField type and multiplaying with 2.It is not passing original value to other file.
– Hiru
Nov 22 '18 at 13:05
add a comment |
I can't see why you need an actual Extraction class. Why not just functions in extraction.py?
– Daniel Roseman
Nov 22 '18 at 12:38
@DanielRoseman Actually i want to perform several task (related to natural language processing) on the one user input string. So i want whole bunch of code in separate python file.
– Hiru
Nov 22 '18 at 12:46
@DanielRoseman i also tried writing direct function but now it is giving me error unsupported operant type. As i am passing "open" which is having FloatField type and multiplaying with 2.It is not passing original value to other file.
– Hiru
Nov 22 '18 at 13:05
I can't see why you need an actual Extraction class. Why not just functions in extraction.py?
– Daniel Roseman
Nov 22 '18 at 12:38
I can't see why you need an actual Extraction class. Why not just functions in extraction.py?
– Daniel Roseman
Nov 22 '18 at 12:38
@DanielRoseman Actually i want to perform several task (related to natural language processing) on the one user input string. So i want whole bunch of code in separate python file.
– Hiru
Nov 22 '18 at 12:46
@DanielRoseman Actually i want to perform several task (related to natural language processing) on the one user input string. So i want whole bunch of code in separate python file.
– Hiru
Nov 22 '18 at 12:46
@DanielRoseman i also tried writing direct function but now it is giving me error unsupported operant type. As i am passing "open" which is having FloatField type and multiplaying with 2.It is not passing original value to other file.
– Hiru
Nov 22 '18 at 13:05
@DanielRoseman i also tried writing direct function but now it is giving me error unsupported operant type. As i am passing "open" which is having FloatField type and multiplaying with 2.It is not passing original value to other file.
– Hiru
Nov 22 '18 at 13:05
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53430893%2fdjango-how-can-i-pass-user-input-value-from-models-py-to-other-fileex-entity-e%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53430893%2fdjango-how-can-i-pass-user-input-value-from-models-py-to-other-fileex-entity-e%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I can't see why you need an actual Extraction class. Why not just functions in extraction.py?
– Daniel Roseman
Nov 22 '18 at 12:38
@DanielRoseman Actually i want to perform several task (related to natural language processing) on the one user input string. So i want whole bunch of code in separate python file.
– Hiru
Nov 22 '18 at 12:46
@DanielRoseman i also tried writing direct function but now it is giving me error unsupported operant type. As i am passing "open" which is having FloatField type and multiplaying with 2.It is not passing original value to other file.
– Hiru
Nov 22 '18 at 13:05