0

I'm new to django framework. I parsed data from WebAPI server to dict:

key is product buys and value is list that contains info about product. Code:

def get_best_products(self):
    dict_of_items = {}

    for x in range (0, self.max_range):
        itemId = self.fresh_data.item[x].itemId
        itemTitle = self.fresh_data.item[x].itemTitle
        photoUrl = self._get_main_item_photo(x)
        itemPrice = self._get_item_price(x)

        dict_of_items[self.fresh_data.item[x].bidsCount] = [itemId, itemTitle, itemPrice, photoUrl]

    return self._sort_parsed_item_data(dict_of_items)

def _sort_parsed_item_data(self, data):
    return OrderedDict(sorted(data.items(), reverse=True, key=lambda t: t[0]))

So i have dict of sorted items by product buys with info as value.

What is best way to put this data to database? Should i build a model? And if yes how to do it? any tips? On internet i can find examples of models that allows to edit data... or "how to build mail registration".

I want to make a model that shows all the data in a table from all the auctions but i dont want to add more. I want to have only 100 records and they will be updated when a buys change. (and maybe later when i build table that table i will try to do... lets say you click on "itemID" it will take you to edit manager, where you can change what you want about that specyfic record).

Is it possible to do with django? or if i want to update just 100 records without change i should just use SQL commands, becouse it seems to be easier? All the examples i saw allows to edit data and add data.... i want to prevent it for now.

But.... Am I allowed to "play" with database without django models when i'm using this framework? That's the main question

1 Answer 1

1

The better way to use Django is using the models, basically Django works on base in something called ORM, Object-Relational mapping, that allows to you work with databases using Classes (models). For more information about how to use it read the docs that Django provide in this tutorial https://docs.djangoproject.com/en/1.11/intro/tutorial01/

Sign up to request clarification or add additional context in comments.

2 Comments

I want to prefill database with 100 records, where and how should i do this function? I have created my model bu actually i can add items by shell or by admin panel. As i said i want to prefill 100 records with prepared in model defaults, and then create another function that uptates that 100 records with prepared data. But where i should create these functions? and how to run it automaticly? let's say when some1 enters the page
@chacken your question is too broad, but yes is much better if you use raw sql and is not a problem if you use it. I recommend read the Django tutorial first so you can implement your functions

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.