Sonata model display - sonata-admin

I have 2 entities, job and invoice. Invoice can have many jobs. Job can have one invoice. So far so good.
When it comes to creating the invoice on the create screen i ask them which company only, this is because i don't want to give them a huge number of jobs and only ones related to the company in question. I then save and send them through to the edit screen where i set the company to read only and do a query to get any invoiceable jobs. However using sonata type model only really gives a select or tick boxes. I'd like to almost show a list view where for each job i can show amount, job number etc, with a check box where i can then associate that job with the invoice
How can i do this and is there a better way of doing this than how i am now?
Thanks

You can use sonata_type_model_list.
$formMapper->add('jobs', 'sonata_type_model_list', []);
It is not mentionned in the documentation but you can see examples of it in use here: http://demo.sonata-project.org/

Related

Implement "add to favorite" in database

I have a question regarding database/system design. We have a table user with user_id and a table school with school_id. We want to implement a feature so that users can add schools to their "favorites list". I already created a third table that contains the relationship between user_id and school_id. Now I have the two following questions:
When a user removes a school from "my favorites" list, should I delete it or keep it in the database but mark it as "deleted"? I want to keep it but it might leave tons of junk data in the table over time.
The front-end design looks similar to like/dislike button on twitter. User can favorite/unfavorite a school with one click. Is there any good way to prevent a bot from constantly hitting the the database by clicking the button?
Thanks in advance!
The answer depends on your application's logic. Both suggestions are ok.
If you need this data sometime in the future or if you are saving history of user actions then you can mark it as "deleted", else you can delete it immediately.
(another approach is mark it as deleted temporarily, and have a periodic job that cleans the table)
I don't have enough experience with this kind of threat, but a simple solution would be is to limit API calls per second per user

Microsoft Access Check in and out

I'm making a database up Microsoft Access to help simplify my job, but I'm relatively inexperienced with it, so I need some help. I'm running Access 2016.
I have a database set up for when students enter the IT Office seeking help, which essentially just records when they enter and what they're here for. So I've put a form on, which lets you enter your information, like your student number, what your problem is, and what your laptop number is. The date and time of your entry are automatically generated by the system clock. The student then presses "Check In", which creates a record based on the information they've just entered to keep track of problems. So here's my question, how would I conveniently give them an option to check back out? I need some way to update the record they've just made, without giving them access to all of the other transactions. I managed to make a list box which makes a list of all the student numbers of people who've entered today, but I'm unsure how to set the check out time of the student when they leave.
Hopefully I've explained that well enough. If you need me to clarify, please pop in a comment.
Thanks everyone.
For users to re-find their record, and not be able to look thru other records - you essentially just need an ID field that they type in; and use that as the query basis for the look up. Possibly the name they entered could be used if you aren't passing out trouble ticket IDs.
The check out info really doesn't have to be a separate table. It can all be part of the same record as the original check in. You can have a separate check out time stamp field that gets populated by a check out button.
The check in and check out may look like separate sides to user - with separate forms that is fine - but behind the scenes I see no reason to have separate tables. keep it simple.
www.CahabaData.com

Constructing a database that collects information from two public surveys and imports answers to a hidden back-end

I am fairly new to constructing databases and was hoping I could get pointed in the right direction on this project. I have self-taught how to use Microsoft Access (my boss is asking that I specifically use this program) and how to "build a database," but I'm stuck on the abstract, specific functions I'm expected to implement. I'll post what I have come up with from all my research to show I've attempted this on my own before asking, but I would greatly appreciate drawing from the expertise of this community. Thanks for all of your time.
Context:
There is a manager survey (1) and an employee survey (2). Every few months, we have leadership roles open up and the managers fill out a survey with all the information regarding the role (opportunity) that they will be in charge of. After all the managers answer, the hopeful employees then review all of the new opportunities, fill out their own survey with some similar questions (and others unique), and indicate what opportunity they are most interested in. Once they fill out their surveys, the data is collected and matched up to the opportunity they wrote they wanted.
My thought process:
The backend can't be editable by those taking the survey - they (managers and employees) should only be able to add a new, non-existent record to their respective table (from the info entered in their survey). The DB would be stored in a
(1) Manager fills survey out (a form created from Mgr_FormShare - a middle man table), import data to backend db table (Mgr_SurveyDataMain)
*Split DB
*Use form as front-end, "properties_data entry: yes"
*Set up relationship between table inside backend and form
(2) Employee reviews opportunities, chooses DESIRED opportunity# and fills in rest of data (in a form created from Emp_FormShare / middle-man table), import data to backend db table (Emp_SurveyDataMain)
*Split DB
*Use form as front-end, "properties_data entry: yes"
*Set up relationship between table inside backend and form
(3) Run query, imports both surveys into one table in backend (ManagerEmpCombineData)
(4) Append an Assigned field in the Mgr_SurveyDataMain (if an opportunity is discovered as chosen, it's "assigned" status goes from no -> yes)
My questions:
Is this the correct way to approach this situation? Is there something I am missing here?
Also, is there a way to ensure all surveys (about 200+ when employee + manager count) will automatically share to the middle-man + only allow one entry per individual? Before splitting, I wanted to make sure that the forms with the properties [DataEntry: "Yes", RecordsSource: "*_FormShare", Each field's control source: linked to respective *_FormShare field] would be enough to make sure that they synced. It's okay if I can't ensure only one use, the sync is the most important aspect.
Thanks again for taking the time to go through my question!

Filtering Functionality Similar to Ebay SQL Count Issue

I am stuck on a database problem for a client, wandering if someone could help me out. I am currently trying to implement filtering functionality so that a user can filter results after they have searched for something. We are using SQL Server 2008. I am working on an electronics e-commerce site and the database is quite large (500,000 plus records). The scenario is this - user goes to our website and types in 'laptop' and clicks search. This brings up the first page of several thousand results. What I want to do is then
filter these results further and present the user with options such as:
Filter By Manufacturer
Dell (10,000)
Acer (2,000)
Lenovo (6,000)
Filter By Colour
Black (7000)
Silver (2000)
The main columns of the database are like this - the primary key is an integer ID
ID Title Manufacturer Colour
The key part of the question is how to get the counts in various categories in an efficient manner. The only way I currently know how to do it is with separate queries. However, should we wish to filter by further categories then this will become very slow - especially as the database grows. My current SQL is this:
select count(*) as ManufacturerCount, Manufacturer from [ProductDB.Product] GROUP BY Manufacturer;
select count(*) as ColourCount, Colour from [ProductDB.Product] GROUP BY Colour;
My question is if I can get the results as a single table using some-kind of join or union and if this would be faster than my current method of issuing multiple queries with the Count(*) function. Thanks for your help, if you require any further information please ask. PS I am wandering how on sites like ebay and amazon manage to do this so fast. In order to understand my problem better if you go onto ebay and type in laptop you will
see a number of filters on the left - this is basically what I am trying to achieve. I don't know how it can be done efficiently when there are many filters. E.g to get functionality equivalent to Ebay I would need about 10 queries and I'm sure that will be slow. I was thinking of creating an intermediate table with all the counts however the intermediate table would have to be continuously updated in order to reflect changes to the database and that would be a problem if there are multiple updates per minute. Thanks.
The "intermediate table" is exactly the way to go. I can guarantee you that no e-commerce site with substantial traffic and large number of products would do what you are suggesting on the fly at every inquiry.
If you are worried about keeping track of changes to products, just do all changes to the product catalog thru stored procs (my preferred method) or else use triggers.
One complication is how you will group things in the intermediate table. If you are only grouping on pre-defined categories and sub-categories that are built into the product hierarchy, then it's fairly easy. It sounds like you are allowing free-text search... if so, how will you manage multiple keywords that result in an unexpected intersection of different categories? One way is to save the keywords searched along with the counts and a time stamp. Then, the next time someone searches on the same keywords, check the intermediate table and if the time stamp is older than some predetermined threshold (say, 5 minutes), return your results to a temp table, query the category counts from the temp table, overwrite the previous counts with the new time stamp, and return the whole enchilada to the web app. Otherwise, skip the temp table and just return the pre-aggregated counts and data records. In this case, you might get some quirky front-end count behavior, like it might say "10 results" in a particular category but then when the user drills down, they actually find 9 or 11. It's happened to me on different sites as a customer and it's really not a big deal.
BTW, I used to work for a well-known e-commerce company and we did things like this.

Django model structure in my project

I'm creating a text-based browser game and need some advice for django model structure. All the examples are from the same project, therefore I will not repeat the same information assuming you've read all the questions from the top to the bottom.
First question
I have an auth app which contains user profile (Player model), alliance app which holds information about all the unions players join and medals app which represents rewards for both players and alliances.
Both users and alliances can have medals assigned so one of the options is to create a M2M field in Player and Alliance models linking to Medal.
Another option would make medals app usable in any other project of mine. This approach includes the use of generic relations in Medal model which links to either Player or Alliance.
Which solution is more django-like or can I do however I want to?
Second question
There will be tasks for players to accomplish. The scenarios of tasks vary greatly, therefore I need some kind of approach to write unique task progress checking code for each task.
Tasks are held in the database containing information about rewards (which are pretty much the same). Where should I write unique code for each task? Maybe I should add some fields and eval() them later? Then all the information will be held in the DB.
Moreover, tasks demand some tracking, for example, imagine a simple task of going to the manual section (just to make sure the player knows where it is). Then I need to register somewhere whether the player has visited manual page or not. I think about creating another model TaskTrackers in task app. Then another question arises. If I should add OneToOne field from Player to TaskTrackers or vice versa?
To sum up, the main question is whether should I add OneToOneFields/M2M fields to user profile model or add OneToOneFields/Foreigneys from target models to User model? The latter would make my apps more reusable, but the first approach may be more logical.
Waiting for answers.
One your first question, you could do either an M2M to Medal, or use a generic foreign key. You'll end up with a couple of join tables with M2M. With the generic foreign key, you won't have any join tables, but you will have the extra query for the content type. So, you may need to set up both ways and see which is going to impact performance more
On your second question, I might take the approach of using a "Task" model with one or more "Step" models that can be set up as an inline formset. Then you'll need a table like "CompletedPlayerTasks" or something like that, which contains the Player ID, Task ID and Step ID. If a Step ID exists in that table, the task has been completed.
It sounds like you need to be able to create custom fields and forms for the Steps of each Task, which isn't terribly hard to do in Django. There are some off the shelf solutions to do this, but you might need to write your own.
Lastly, I wouldn't name the app that holds your user profiles "auth", which could cause a namespace problem with Django's contrib.auth app. I would name it "profiles", just so it's more obvious what that app does and contains.
Hope that gives you some ideas.

Resources